Android Open Source - growthpush-android Alert Fragment






From Project

Back to project page growthpush-android.

License

The source code is released under:

Apache License

If you think the Android project growthpush-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.growthpush.view;
/* w w w .j  a v  a 2s .  c  o m*/
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnKeyListener;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.KeyEvent;

/**
 * Created by Shigeru Ogawa on 13/08/12.
 */
public class AlertFragment extends DialogFragment implements DialogInterface.OnClickListener {

  private DialogCallback listener;

  public AlertFragment() {
    super();
  }

  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {

    Dialog dialog = generateAlertDialog();
    if (dialog == null)
      return super.onCreateDialog(savedInstanceState);

    return dialog;

  }

  private Dialog generateAlertDialog() {

    PackageManager packageManager = getActivity().getPackageManager();
    ApplicationInfo applicationInfo = null;
    try {
      applicationInfo = packageManager.getApplicationInfo(getActivity().getPackageName(), 0);
    } catch (NameNotFoundException e) {
      return null;
    }

    Dialog dialog = new AlertDialog.Builder(getActivity()).setIcon(packageManager.getApplicationIcon(applicationInfo))
        .setTitle(packageManager.getApplicationLabel(applicationInfo)).setMessage(getArguments().getString("message"))
        .setPositiveButton("OK", this).setNegativeButton("Cancel", this).create();
    dialog.setOnKeyListener(new OnKeyListener() {
      @Override
      public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {

        if (keyCode == KeyEvent.KEYCODE_BACK)
          if (listener != null)
            listener.onClickNegative(dialog);

        return false;
      }
    });

    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    dialog.setCanceledOnTouchOutside(false);

    return dialog;
  }

  @Override
  public void onAttach(Activity activity) {
    super.onAttach(activity);

    if (activity instanceof AlertActivity)
      this.listener = (DialogCallback) activity;

  }

  @Override
  public void onClick(DialogInterface dialog, int which) {

    switch (which) {
    case DialogInterface.BUTTON_POSITIVE:
      if (this.listener != null)
        listener.onClickPositive(dialog);
      break;
    case DialogInterface.BUTTON_NEGATIVE:
      if (this.listener != null)
        listener.onClickNegative(dialog);
      break;
    default:
      break;
    }

  }

}




Java Source Code List

com.growthpush.BroadcastReceiver.java
com.growthpush.GrowthPushException.java
com.growthpush.GrowthPush.java
com.growthpush.Logger.java
com.growthpush.Preference.java
com.growthpush.Thread.java
com.growthpush.bridge.ExternalFrameworkBridge.java
com.growthpush.bridge.ExternalFrameworkBroadcastReceiver.java
com.growthpush.growthpushsample.MainActivity.java
com.growthpush.handler.BaseReceiveHandler.java
com.growthpush.handler.DefaultReceiveHandler.java
com.growthpush.handler.OnlyAlertReceiveHandler.java
com.growthpush.handler.OnlyNotificationReceiveHandler.java
com.growthpush.handler.ReceiveHandler.java
com.growthpush.model.ClientStatus.java
com.growthpush.model.Client.java
com.growthpush.model.Environment.java
com.growthpush.model.Error.java
com.growthpush.model.Event.java
com.growthpush.model.Model.java
com.growthpush.model.Tag.java
com.growthpush.utils.DeviceUtils.java
com.growthpush.utils.IOUtils.java
com.growthpush.utils.PermissionUtils.java
com.growthpush.utils.SystemUtils.java
com.growthpush.view.AlertActivity.java
com.growthpush.view.AlertFragment.java
com.growthpush.view.DialogCallback.java