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:org.deviceconnect.android.deviceplugin.uvc.fragment.UVCDeviceListFragment.java

/**
 * Added the view at ListView.//w  ww.j a  v  a 2s .  c om
 */
private void addFooterView() {
    final Activity activity = getActivity();
    if (activity == null) {
        return;
    }
    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            UVCDeviceManager mgr = getManager();
            if (mgr == null) {
                return;
            }
            LayoutInflater inflater = activity.getLayoutInflater();
            if (mFooterView != null) {
                mListView.removeFooterView(mFooterView);
            }
            if (mgr.getDeviceList().size() == 0) {
                mFooterView = inflater.inflate(R.layout.item_uvc_error, null);
                mListView.addFooterView(mFooterView);
            }
        }
    });
}

From source file:com.github.pockethub.ui.gist.GistFragment.java

private void updateFiles(Gist gist) {
    final Activity activity = getActivity();
    if (activity == null)
        return;//from  ww w  .  jav  a  2s .c  o  m

    for (View header : fileHeaders)
        adapter.removeHeader(header);
    fileHeaders.clear();

    Map<String, GistFile> files = gist.files;
    if (files == null || files.isEmpty())
        return;

    final LayoutInflater inflater = activity.getLayoutInflater();
    final Typeface octicons = TypefaceUtils.getOcticons(activity);
    for (GistFile file : files.values()) {
        View fileView = inflater.inflate(R.layout.gist_file_item, null);
        ((TextView) fileView.findViewById(R.id.tv_file)).setText(file.filename);
        ((TextView) fileView.findViewById(R.id.tv_file_icon)).setTypeface(octicons);
        adapter.addHeader(fileView, file, true);
        fileHeaders.add(fileView);
    }
}

From source file:de.spiritcroc.ownlog.ui.fragment.ImportLogFragment.java

private void loadImportDb(String passwd) {
    if (mDbHelper == null) {
        mDbHelper = new ExternalDbReadHelper(mImportFiles.logDbFile.getAbsolutePath());
    }/*from ww w . j  av a 2 s.  c o  m*/
    SQLiteDatabase db = null;
    try {
        db = mDbHelper.getReadableDatabase(passwd);
    } catch (SQLiteException e) {
        e.printStackTrace();
    } catch (DbHelper.UnsupportedUpgradeException e) {
        Log.w(TAG, "Import: unsupported upgrade from " + e.oldVersion);
        // Unsupported db version: notify user and close activity
        invalidImport();
        // No more prompting for password
        return;
    }
    if (db != null) {
        new LoadBackupTask(db).execute();
    } else {
        // Prompt for password
        final Activity activity = getActivity();
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        final View view = activity.getLayoutInflater().inflate(R.layout.dialog_request_password, null);

        final EditText editPassword = (EditText) view.findViewById(R.id.edit_password);

        final AlertDialog alertDialog = builder.setTitle(R.string.import_dialog_request_password).setView(view)
                .setCancelable(false)
                .setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        loadImportDb(editPassword.getText().toString());
                    }
                }).setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        activity.finish();
                        mDbHelper.close();
                    }
                }).show();

        // Edit text requires user interaction, so show keyboard
        alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    }
}

From source file:com.github.pockethub.android.ui.gist.GistFragment.java

private void updateFiles(Gist gist) {
    final Activity activity = getActivity();
    if (activity == null) {
        return;/*from  www .j a v  a2s  . co m*/
    }

    for (View header : fileHeaders) {
        adapter.removeHeader(header);
    }
    fileHeaders.clear();

    Map<String, GistFile> files = gist.files();
    if (files == null || files.isEmpty()) {
        return;
    }

    final LayoutInflater inflater = activity.getLayoutInflater();
    for (GistFile file : files.values()) {
        View fileView = inflater.inflate(R.layout.gist_file_item, null);
        ((TextView) fileView.findViewById(R.id.tv_file)).setText(file.filename());
        adapter.addHeader(fileView, file, true);
        fileHeaders.add(fileView);
    }
}

From source file:org.sufficientlysecure.keychain.ui.dialog.AddEditKeyserverDialogFragment.java

@NonNull
@Override//w  w  w .  j a va2s.c om
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Activity activity = getActivity();

    mMessenger = getArguments().getParcelable(ARG_MESSENGER);
    mDialogAction = (DialogAction) getArguments().getSerializable(ARG_ACTION);
    mPosition = getArguments().getInt(ARG_POSITION);

    CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(activity);

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

    mKeyserverEditText = (EditText) view.findViewById(R.id.keyserver_url_edit_text);
    mKeyserverEditTextLayout = (TextInputLayout) view.findViewById(R.id.keyserver_url_edit_text_layout);
    mKeyserverEditOnionText = (EditText) view.findViewById(R.id.keyserver_onion_edit_text);
    mKeyserverEditOnionTextLayout = (TextInputLayout) view.findViewById(R.id.keyserver_onion_edit_text_layout);
    mVerifyKeyserverCheckBox = (CheckBox) view.findViewById(R.id.verify_connection_checkbox);
    mOnlyTrustedKeyserverCheckBox = (CheckBox) view.findViewById(R.id.only_trusted_keyserver_checkbox);
    mVerifyKeyserverCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mOnlyTrustedKeyserverCheckBox.setEnabled(isChecked);
        }
    });

    switch (mDialogAction) {
    case ADD: {
        alert.setTitle(R.string.add_keyserver_dialog_title);
        break;
    }
    case EDIT: {
        alert.setTitle(R.string.edit_keyserver_dialog_title);
        ParcelableHkpKeyserver keyserver = getArguments().getParcelable(ARG_KEYSERVER);
        mKeyserverEditText.setText(keyserver.getUrl());
        mKeyserverEditOnionText.setText(keyserver.getOnion());
        break;
    }
    }

    // we don't want dialog to be dismissed on click for keyserver addition or edit,
    // thereby requiring the hack seen below and in onStart
    alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            // we need to have an empty listener to prevent errors on some devices as mentioned
            // at http://stackoverflow.com/q/13746412/3000919
            // actual listener set in onStart for adding keyservers or editing them
        }
    });

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

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

    switch (mDialogAction) {
    case EDIT: {
        alert.setNeutralButton(R.string.label_keyserver_dialog_delete, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                deleteKeyserver(mPosition);
            }
        });
        break;
    }
    case ADD: {
        // do nothing
        break;
    }
    }

    // Hack to open keyboard.
    // This is the only method that I found to work across all Android versions
    // http://turbomanage.wordpress.com/2012/05/02/show-soft-keyboard-automatically-when-edittext-receives-focus/
    // Notes: * onCreateView can't be used because we want to add buttons to the dialog
    //        * opening in onActivityCreated does not work on Android 4.4
    mKeyserverEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            mKeyserverEditText.post(new Runnable() {
                @Override
                public void run() {
                    InputMethodManager imm = (InputMethodManager) getActivity()
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.showSoftInput(mKeyserverEditText, InputMethodManager.SHOW_IMPLICIT);
                }
            });
        }
    });
    mKeyserverEditText.requestFocus();

    mKeyserverEditText.setImeActionLabel(getString(android.R.string.ok), EditorInfo.IME_ACTION_DONE);
    mKeyserverEditText.setOnEditorActionListener(this);

    return alert.show();
}

From source file:org.sufficientlysecure.keychain.ui.dialog.AddEditSmartPGPAuthorityDialogFragment.java

@NonNull
@Override//from  ww  w  .j  a  v a 2s .  c o  m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Activity activity = getActivity();

    mMessenger = getArguments().getParcelable(IN_MESSENGER);
    mAction = (Action) getArguments().getSerializable(IN_ACTION);
    mPosition = getArguments().getInt(IN_POSITION);
    if (getArguments().getString(IN_URI) == null)
        mURI = null;
    else
        mURI = Uri.parse(getArguments().getString(IN_URI));

    CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(activity);

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

    mAuthorityAliasText = (EditText) view.findViewById(R.id.smartpgp_authority_alias_edit_text);
    mAuthorityAliasTextLayout = (TextInputLayout) view
            .findViewById(R.id.smartpgp_authority_alias_edit_text_layout);
    mAuthorityAdd = (Button) view.findViewById(R.id.smartpgp_authority_filename);

    mAuthorityAdd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            FileHelper.openDocument(AddEditSmartPGPAuthorityDialogFragment.this, null, "*/*", false,
                    EncryptFilesFragment.REQUEST_CODE_INPUT);
        }
    });

    mAuthorityAliasText.setText(getArguments().getString(IN_ALIAS));

    switch (mAction) {
    case ADD:
        alert.setTitle(R.string.add_smartpgp_authority_dialog_title);
        break;
    case EDIT:
    case DELETE:
        alert.setTitle(R.string.show_smartpgp_authority_dialog_title);
        break;
    }

    // we don't want dialog to be dismissed on click for keyserver addition or edit,
    // thereby requiring the hack seen below and in onStart
    alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            // we need to have an empty listener to prevent errors on some devices as mentioned
            // at http://stackoverflow.com/q/13746412/3000919
            // actual listener set in onStart for adding keyservers or editing them
            dismiss();
        }
    });

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

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

    switch (mAction) {
    case EDIT:
    case DELETE:
        alert.setNeutralButton(R.string.label_smartpgp_authority_dialog_delete,
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        deleteAuthority();
                    }
                });
        break;
    }

    // Hack to open keyboard.
    // This is the only method that I found to work across all Android versions
    // http://turbomanage.wordpress.com/2012/05/02/show-soft-keyboard-automatically-when-edittext-receives-focus/
    // Notes: * onCreateView can't be used because we want to add buttons to the dialog
    //        * opening in onActivityCreated does not work on Android 4.4
    mAuthorityAliasText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            mAuthorityAliasText.post(new Runnable() {
                @Override
                public void run() {
                    InputMethodManager imm = (InputMethodManager) getActivity()
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.showSoftInput(mAuthorityAliasText, InputMethodManager.SHOW_IMPLICIT);
                }
            });
        }
    });
    mAuthorityAliasText.requestFocus();

    mAuthorityAliasText.setImeActionLabel(getString(android.R.string.ok), EditorInfo.IME_ACTION_DONE);
    mAuthorityAliasText.setOnEditorActionListener(this);

    return alert.show();
}

From source file:com.breadwallet.BreadWalletApp.java

/**
 * Shows a custom toast using the given string as a paramater,
 *
 * @param message the message to be shown in the custom toast
 *//*from www .  ja  v  a 2  s  .c  o m*/

public void showCustomToast(Activity app, String message, int yOffSet, int duration, int color) {
    if (toast == null)
        toast = new Toast(getApplicationContext());
    if (MainActivity.appInBackground)
        return;

    if (customToastAvailable || !oldMessage.equals(message)) {
        oldMessage = message;
        customToastAvailable = false;
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                customToastAvailable = true;
            }
        }, 1000);
        LayoutInflater inflater = app.getLayoutInflater();
        View layout = inflater.inflate(R.layout.toast, (ViewGroup) app.findViewById(R.id.toast_layout_root));
        if (color == 1) {
            layout.setBackgroundResource(R.drawable.toast_layout_black);
        }
        TextView text = (TextView) layout.findViewById(R.id.toast_text);
        text.setText(message);
        toast.setGravity(Gravity.BOTTOM, 0, yOffSet);
        toast.setDuration(duration);
        toast.setView(layout);
        toast.show();
    }
}

From source file:dynamite.zafroshops.app.fragment.ZopItemFragment.java

private void setZop(Activity activity) {
    if (zop != null && zop.Location != null && MainActivity.LastLocation != null) {
        float[] results = new float[1];
        Location.distanceBetween(MainActivity.LastLocation.Latitude, MainActivity.LastLocation.Longitude,
                zop.Location.Latitude, zop.Location.Longitude, results);
        zop.Distance = results[0] / 1000;
    }/*w  w w .j a  v a  2 s.  com*/

    LinearLayout itemZop = (LinearLayout) activity.findViewById(R.id.itemZop);
    RelativeLayout loader = (RelativeLayout) activity.findViewById(R.id.relativeLayoutLoader);
    ArrayList<MobileOpeningHourData> ohs = zop.getGroupedOpeningHours();

    if (ohs != null) {
        setLayout(activity.getLayoutInflater(), itemZop, zop, loader);
    }
}

From source file:org.typhonrt.android.java6.data.option.control.OptionModelDrawerControl.java

public OptionModelDrawerControl(Activity activity) {
    optionModelList = new ArrayList<IOptionModel>();
    updateNotify = new AtomicBoolean();

    DrawerLayout drawerLayout = (DrawerLayout) activity.findViewById(R.id.drawer_layout);

    drawerListView = (ListView) activity.findViewById(R.id.left_drawer);

    Resources resources = activity.getResources();

    drawerLayout.setScrimColor(resources.getColor(R.color.drawer_scrim_color));

    // Handle ActionBarDrawerToggle

    ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(activity, drawerLayout,
            (Toolbar) activity.findViewById(R.id.toolbar), R.string.drawer_open, R.string.drawer_close);

    actionBarDrawerToggle.syncState();//from w  w w.  ja va 2s  .c  om

    // Handle different Drawer States :D
    drawerLayout.setDrawerListener(actionBarDrawerToggle);

    // Setup header views
    LayoutInflater inflater = activity.getLayoutInflater();
    headerView = inflater.inflate(R.layout.drawer_headerview, null);

    // Set the adapter for the list view
    drawerListView
            .setAdapter(optionListAdapter = new OptionModelAdapter(activity, optionModelList, updateNotify));
}

From source file:org.retroshare.android.ConversationFragment.java

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

    final Bundle arguments = getArguments();
    if (arguments.containsKey(CONVERSATION_ID_EXTRA_KEY))
        conversationId = arguments.getParcelable(CONVERSATION_ID_EXTRA_KEY);
    else/*from  w  w w .  ja  v  a  2 s .  c  o m*/
        throw new RuntimeException(TAG() + " need arguments contains valid value for "
                + ConversationFragment.CONVERSATION_ID_EXTRA_KEY);

    chatImageGetter = new HtmlBase64ImageGetter(getResources());
    mInflater = a.getLayoutInflater();
}