Example usage for android.app Activity getLayoutInflater

List of usage examples for android.app Activity getLayoutInflater

Introduction

In this page you can find the example usage for android.app Activity getLayoutInflater.

Prototype

@NonNull
public LayoutInflater getLayoutInflater() 

Source Link

Document

Convenience for calling android.view.Window#getLayoutInflater .

Usage

From source file:id.nci.stm_9.PassphraseDialogFragment.java

/**
 * Creates dialog//from ww  w .j  a  v a 2 s  .c  o m
 */
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Activity activity = getActivity();
    final long secretKeyId = getArguments().getLong(ARG_SECRET_KEY_ID);
    mMessenger = getArguments().getParcelable(ARG_MESSENGER);

    AlertDialog.Builder alert = new AlertDialog.Builder(activity);

    alert.setTitle(R.string.title_authentication);

    final PGPSecretKey secretKey;

    //        if (secretKeyId == Id.key.symmetric || secretKeyId == Id.key.none) {
    if (secretKeyId == -1 || secretKeyId == 0) {
        secretKey = null;
        alert.setMessage(R.string.passphrase_for_symmetric_encryption);
    } else {
        // TODO: by master key id???
        secretKey = PgpKeyHelper.getMasterKey(ProviderHelper.getPGPSecretKeyRingByKeyId(activity, secretKeyId));
        // secretKey = PGPHelper.getMasterKey(PGPMain.getSecretKeyRing(secretKeyId));

        if (secretKey == null) {
            alert.setTitle(R.string.title_key_not_found);
            alert.setMessage(getString(R.string.key_not_found, secretKeyId));
            alert.setPositiveButton(android.R.string.ok, new OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dismiss();
                }
            });
            alert.setCancelable(false);
            canKB = false;
            return alert.create();
        }
        String userId = PgpKeyHelper.getMainUserIdSafe(activity, secretKey);

        Log.d("stm-9", "User id: '" + userId + "'");
        alert.setMessage(getString(R.string.passphrase_for, userId));
    }

    LayoutInflater inflater = activity.getLayoutInflater();
    View view = inflater.inflate(R.layout.passphrase, null);
    alert.setView(view);

    mPassphraseEditText = (EditText) view.findViewById(R.id.passphrase_passphrase);

    alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int id) {
            dismiss();
            long curKeyIndex = 1;
            boolean keyOK = true;
            String passPhrase = mPassphraseEditText.getText().toString();
            long keyId;
            PGPSecretKey clickSecretKey = secretKey;

            if (clickSecretKey != null) {
                while (keyOK == true) {
                    if (clickSecretKey != null) { // check again for loop
                        try {
                            PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder()
                                    .setProvider(BouncyCastleProvider.PROVIDER_NAME)
                                    .build(passPhrase.toCharArray());
                            PGPPrivateKey testKey = clickSecretKey.extractPrivateKey(keyDecryptor);
                            if (testKey == null) {
                                if (!clickSecretKey.isMasterKey()) {
                                    Toast.makeText(activity, R.string.error_could_not_extract_private_key,
                                            Toast.LENGTH_SHORT).show();

                                    sendMessageToHandler(MESSAGE_CANCEL);
                                    return;
                                } else {
                                    clickSecretKey = PgpKeyHelper.getKeyNum(
                                            ProviderHelper.getPGPSecretKeyRingByKeyId(activity, secretKeyId),
                                            curKeyIndex);
                                    curKeyIndex++; // does post-increment work like C?
                                    continue;
                                }
                            } else {
                                keyOK = false;
                            }
                        } catch (PGPException e) {
                            Toast.makeText(activity, R.string.wrong_passphrase, Toast.LENGTH_SHORT).show();

                            sendMessageToHandler(MESSAGE_CANCEL);
                            return;
                        }
                    } else {
                        Toast.makeText(activity, R.string.error_could_not_extract_private_key,
                                Toast.LENGTH_SHORT).show();

                        sendMessageToHandler(MESSAGE_CANCEL);
                        return; // ran out of keys to try
                    }
                }
                keyId = secretKey.getKeyID();
            } else {
                //                    keyId = Id.key.symmetric;
                keyId = -1;
            }

            // cache the new passphrase
            Log.d("stm-9", "Everything okay! Caching entered passphrase");
            PassphraseCacheService.addCachedPassphrase(activity, keyId, passPhrase);
            if (keyOK == false && clickSecretKey.getKeyID() != keyId) {
                PassphraseCacheService.addCachedPassphrase(activity, clickSecretKey.getKeyID(), passPhrase);
            }

            sendMessageToHandler(MESSAGE_OKAY);
        }
    });

    alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });

    canKB = true;
    return alert.create();
}

From source file:com.amaze.filemanager.utils.Futils.java

public void showProps(final HFile f, final Activity c, int theme1) {
    String date = null;/*  w  w w.  j av a 2s.com*/
    try {
        date = getdate(f.lastModified());
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (SmbException e) {
        e.printStackTrace();
    }
    String items = getString(c, R.string.calculating), size = getString(c, R.string.calculating), name, parent;
    name = f.getName();
    parent = f.getReadablePath(f.getParent());
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(c);
    String fabskin = PreferenceUtils.getAccentString(sp);
    MaterialDialog.Builder a = new MaterialDialog.Builder(c);
    a.title(getString(c, R.string.properties));
    if (theme1 == 1)
        a.theme(Theme.DARK);

    View v = c.getLayoutInflater().inflate(R.layout.properties_dialog, null);
    v.findViewById(R.id.appX).setVisibility(View.GONE);
    a.customView(v, true);
    a.positiveText(R.string.copy_path);
    a.negativeText(getString(c, R.string.md5_2));
    a.positiveColor(Color.parseColor(fabskin));
    a.negativeColor(Color.parseColor(fabskin));
    a.neutralText(R.string.cancel);
    a.neutralColor(Color.parseColor(fabskin));
    a.callback(new MaterialDialog.ButtonCallback() {
        @Override
        public void onPositive(MaterialDialog materialDialog) {
            copyToClipboard(c, f.getPath());
            Toast.makeText(c, c.getResources().getString(R.string.pathcopied), Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onNegative(MaterialDialog materialDialog) {
        }
    });
    MaterialDialog materialDialog = a.build();
    materialDialog.show();
    new GenerateMD5Task(materialDialog, (f), name, parent, size, items, date, c, v).execute(f.getPath());
}

From source file:org.uguess.android.sysinfo.ProcessManager.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.proc_lst_view, container, false);

    ListView listView = (ListView) rootView.findViewById(android.R.id.list);

    registerForContextMenu(listView);/* www . ja v a  2  s.  co  m*/

    View listHeader = rootView.findViewById(R.id.list_head);
    listHeader.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            boolean showWarning = Util.getBooleanOption(getActivity(), PSTORE_PROCESSMANAGER,
                    PREF_KEY_SHOW_KILL_WARN);

            if (showWarning) {
                OnClickListener listener = new OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        endAllExcept(null);
                    }
                };

                new AlertDialog.Builder(getActivity()).setTitle(R.string.warning)
                        .setMessage(R.string.end_all_prompt).setPositiveButton(android.R.string.ok, listener)
                        .setNegativeButton(android.R.string.cancel, null).create().show();
            } else {
                endAllExcept(null);
            }

        }
    });

    ArrayAdapter<ProcessItem> adapter = new ArrayAdapter<ProcessItem>(getActivity(), R.layout.proc_item) {

        public android.view.View getView(int position, android.view.View convertView,
                android.view.ViewGroup parent) {
            Activity ctx = getActivity();

            View view;
            TextView txt_name, txt_mem, txt_cpu;
            ImageView img_type;

            if (convertView == null) {
                view = ctx.getLayoutInflater().inflate(R.layout.proc_item, parent, false);
            } else {
                view = convertView;
            }

            if (position >= getCount()) {
                return view;
            }

            ProcessItem itm = getItem(position);

            img_type = (ImageView) view.findViewById(R.id.img_proc_icon);
            txt_name = (TextView) view.findViewById(R.id.txt_proc_name);
            txt_mem = (TextView) view.findViewById(R.id.txt_mem);
            txt_cpu = (TextView) view.findViewById(R.id.txt_cpu);

            boolean showMem = Util.getBooleanOption(ctx, PSTORE_PROCESSMANAGER, PREF_KEY_SHOW_MEM);
            boolean showCpu = Util.getBooleanOption(ctx, PSTORE_PROCESSMANAGER, PREF_KEY_SHOW_CPU);

            String lb = itm.label == null ? itm.procInfo.processName : itm.label;
            if (itm.sys) {
                lb += " *"; //$NON-NLS-1$
            } else if (ignoreList.contains(itm.procInfo.processName)) {
                lb += " ~"; //$NON-NLS-1$
            }
            txt_name.setText(lb);

            switch (itm.procInfo.importance) {
            case RunningAppProcessInfo.IMPORTANCE_FOREGROUND:
                txt_name.setTextColor(Color.CYAN);
                break;
            case RunningAppProcessInfo.IMPORTANCE_PERCEPTIBLE:
            case RunningAppProcessInfo.IMPORTANCE_VISIBLE:
                txt_name.setTextColor(Color.GREEN);
                break;
            case RunningAppProcessInfo.IMPORTANCE_SERVICE:
                txt_name.setTextColor(Color.GRAY);
                break;
            case RunningAppProcessInfo.IMPORTANCE_BACKGROUND:
                txt_name.setTextColor(Color.YELLOW);
                break;
            case RunningAppProcessInfo.IMPORTANCE_EMPTY:
            default:
                txt_name.setTextColor(Color.WHITE);
                break;
            }

            img_type.setImageDrawable(itm.icon);

            if (showMem) {
                txt_mem.setVisibility(View.VISIBLE);
                txt_mem.setText(itm.mem);
            } else {
                txt_mem.setVisibility(View.GONE);
            }

            if (showCpu) {
                txt_cpu.setVisibility(View.VISIBLE);

                long delta = itm.lastcputime == 0 ? 0 : (itm.cputime - itm.lastcputime);

                long cu = totalDelta == 0 ? 0 : (delta * 100 / totalDelta);

                if (cu < 0) {
                    cu = 0;
                }
                if (cu > 100) {
                    cu = 100;
                }

                txt_cpu.setText(String.valueOf(cu));
            } else {
                txt_cpu.setVisibility(View.GONE);
            }

            return view;
        }
    };

    setListAdapter(adapter);

    return rootView;
}

From source file:org.uguess.android.sysinfo.ApplicationManager.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.app_lst_view, container, false);

    ((Button) rootView.findViewById(R.id.btn_export)).setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            doExport();//  w  w  w  .j a  v a  2  s. c  o  m
        }
    });

    ((Button) rootView.findViewById(R.id.btn_sel_all)).setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            toggleAllSelection(true);
        }
    });

    ((Button) rootView.findViewById(R.id.btn_desel_all)).setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            toggleAllSelection(false);
        }
    });

    ListView lstApps = (ListView) rootView.findViewById(android.R.id.list);

    lstApps.setFastScrollEnabled(true);

    registerForContextMenu(lstApps);

    ArrayAdapter<AppInfoHolder> adapter = new ArrayAdapter<AppInfoHolder>(getActivity(), R.layout.app_item) {

        public android.view.View getView(int position, android.view.View convertView,
                android.view.ViewGroup parent) {
            View view;
            TextView txt_name, txt_size, txt_ver, txt_time;
            ImageView img_type;
            CheckBox ckb_app;

            Activity ctx = getActivity();

            if (convertView == null) {
                view = ctx.getLayoutInflater().inflate(R.layout.app_item, parent, false);
            } else {
                view = convertView;
            }

            if (position >= getCount()) {
                return view;
            }

            AppInfoHolder itm = getItem(position);

            txt_name = (TextView) view.findViewById(R.id.app_name);
            if (itm.label != null) {
                txt_name.setText(itm.label);
            } else {
                txt_name.setText(itm.appInfo.packageName);
            }

            if (Util.getBooleanOption(ctx, PSTORE_APPMANAGER, PREF_KEY_SHOW_BACKUP_STATE)) {
                switch (itm.backupState) {
                case 1:
                    txt_name.setTextColor(Color.YELLOW);
                    break;
                case 2:
                    txt_name.setTextColor(0xff00bb00);
                    break;
                case 3:
                    txt_name.setTextColor(0xffF183BD);
                    break;
                default:
                    txt_name.setTextColor(Color.WHITE);
                    break;
                }
            } else {
                txt_name.setTextColor(Color.WHITE);
            }

            txt_ver = (TextView) view.findViewById(R.id.app_version);
            txt_ver.setText(itm.version);

            txt_size = (TextView) view.findViewById(R.id.app_size);
            if (Util.getBooleanOption(ctx, PSTORE_APPMANAGER, PREF_KEY_SHOW_SIZE)) {
                txt_size.setVisibility(View.VISIBLE);

                if (itm.size != null) {
                    txt_size.setText(itm.size);
                } else {
                    txt_size.setText(R.string.computing);
                }
            } else {
                txt_size.setVisibility(View.GONE);
            }

            txt_time = (TextView) view.findViewById(R.id.app_time);
            if (Util.getBooleanOption(ctx, PSTORE_APPMANAGER, PREF_KEY_SHOW_DATE)) {
                txt_time.setVisibility(View.VISIBLE);

                if (itm.appInfo.sourceDir != null) {
                    File f = new File(itm.appInfo.sourceDir);
                    txt_time.setText(DateUtils.formatDateTime(ctx, f.lastModified(), DateUtils.FORMAT_SHOW_YEAR
                            | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME));
                } else {
                    txt_time.setText(R.string.unknown);
                }
            } else {
                txt_time.setVisibility(View.GONE);
            }

            img_type = (ImageView) view.findViewById(R.id.img_app_icon);
            if (Util.getBooleanOption(ctx, PSTORE_APPMANAGER, PREF_KEY_SHOW_ICON)) {
                img_type.setVisibility(View.VISIBLE);

                if (itm.icon != null) {
                    img_type.setImageDrawable(itm.icon);
                } else {
                    try {
                        img_type.setImageDrawable(ctx.getPackageManager().getDefaultActivityIcon());
                    } catch (Exception fe) {
                        img_type.setImageDrawable(null);

                        Log.e(ApplicationManager.class.getName(), fe.getLocalizedMessage());
                    }
                }
            } else {
                img_type.setVisibility(View.GONE);
            }

            ckb_app = (CheckBox) view.findViewById(R.id.ckb_app);
            ckb_app.setTag(position);
            ckb_app.setChecked(itm.checked);
            ckb_app.setOnCheckedChangeListener(checkListener);

            View imgLock = view.findViewById(R.id.img_lock);
            imgLock.setVisibility(itm.isPrivate ? View.VISIBLE : View.GONE);

            return view;
        }
    };

    setListAdapter(adapter);

    return rootView;
}

From source file:org.allseen.lsf.sampleapp.view.MainFragment.java

private void wifiConnectionStateUpdate(boolean connected) {
    final Activity activity = getActivity();

    postUpdateControllerDisplay();// w w  w.  ja va2  s . c  o m

    if (connected) {
        handler.post(new Runnable() {
            @Override
            public void run() {
                //                   Log.d(SampleAppActivity.TAG, "wifi connected");

                postInForeground(new Runnable() {
                    @Override
                    public void run() {
                        //                         Log.d(SampleAppActivity.TAG_TRACE, "Starting system");

                        LightingDirector.get().setNetworkConnectionStatus(true);

                        if (isControllerServiceEnabled()) {
                            //                           Log.d(SampleAppActivity.TAG_TRACE, "Starting bundled controller service");
                            setControllerServiceStarted(true);
                        }

                        if (wifiDisconnectAlertDialog != null) {
                            wifiDisconnectAlertDialog.dismiss();
                            wifiDisconnectAlertDialog = null;
                        }
                    }
                });
            }
        });
    } else {
        handler.post(new Runnable() {
            @Override
            public void run() {
                //             Log.d(SampleAppActivity.TAG, "wifi disconnected");

                postInForeground(new Runnable() {
                    @Override
                    public void run() {
                        if (wifiDisconnectAlertDialog == null) {
                            //                       Log.d(SampleAppActivity.TAG, "Stopping system");

                            LightingDirector.get().setNetworkConnectionStatus(false);

                            setControllerServiceStarted(false);

                            View view = activity.getLayoutInflater().inflate(R.layout.view_loading, null);
                            ((TextView) view.findViewById(R.id.loadingText1))
                                    .setText(activity.getText(R.string.no_wifi_message));
                            ((TextView) view.findViewById(R.id.loadingText2))
                                    .setText(activity.getText(R.string.searching_wifi));

                            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity);
                            alertDialogBuilder.setView(view);
                            alertDialogBuilder.setTitle(R.string.no_wifi);
                            alertDialogBuilder.setCancelable(false);
                            wifiDisconnectAlertDialog = alertDialogBuilder.create();
                            wifiDisconnectAlertDialog.show();
                        }
                    }
                });
            }
        });
    }
}

From source file:im.vector.fragments.VectorSettingsPreferencesFragment.java

private void displayTextSizeSelection(final Activity activity) {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    LayoutInflater inflater = activity.getLayoutInflater();

    View layout = inflater.inflate(R.layout.text_size_selection, null);
    builder.setTitle(R.string.font_size);
    builder.setView(layout);//  w w w  .  j  ava  2s.  com

    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
        }
    });

    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
        }
    });

    final AlertDialog dialog = builder.create();
    dialog.show();

    LinearLayout linearLayout = layout.findViewById(R.id.text_selection_group_view);

    int childCount = linearLayout.getChildCount();

    String scaleText = VectorApp.getFontScale();

    for (int i = 0; i < childCount; i++) {
        View v = linearLayout.getChildAt(i);

        if (v instanceof CheckedTextView) {
            final CheckedTextView checkedTextView = (CheckedTextView) v;
            checkedTextView.setChecked(TextUtils.equals(checkedTextView.getText(), scaleText));

            checkedTextView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                    VectorApp.updateFontScale(checkedTextView.getText().toString());
                    activity.startActivity(activity.getIntent());
                    activity.finish();
                }
            });
        }
    }
}