Example usage for android.view LayoutInflater from

List of usage examples for android.view LayoutInflater from

Introduction

In this page you can find the example usage for android.view LayoutInflater from.

Prototype

public static LayoutInflater from(Context context) 

Source Link

Document

Obtains the LayoutInflater from the given context.

Usage

From source file:android.support.v7.app.AppCompatDelegateImplV7.java

@Override
ActionMode startSupportActionModeFromWindow(ActionMode.Callback callback) {
    if (mActionMode != null) {
        mActionMode.finish();/*from  w  ww  . jav a 2s  .c o m*/
    }

    final ActionMode.Callback wrappedCallback = new ActionModeCallbackWrapper(callback);
    final Context context = getActionBarThemedContext();

    if (mActionModeView == null) {
        if (mIsFloating) {
            mActionModeView = new ActionBarContextView(context);
            mActionModePopup = new PopupWindow(context, null, R.attr.actionModePopupWindowStyle);
            mActionModePopup.setContentView(mActionModeView);
            mActionModePopup.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);

            TypedValue heightValue = new TypedValue();
            mContext.getTheme().resolveAttribute(R.attr.actionBarSize, heightValue, true);
            final int height = TypedValue.complexToDimensionPixelSize(heightValue.data,
                    mContext.getResources().getDisplayMetrics());
            mActionModeView.setContentHeight(height);
            mActionModePopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
            mShowActionModePopup = new Runnable() {
                public void run() {
                    mActionModePopup.showAtLocation(mActionModeView, Gravity.TOP | Gravity.FILL_HORIZONTAL, 0,
                            0);
                }
            };
        } else {
            ViewStubCompat stub = (ViewStubCompat) mSubDecor.findViewById(R.id.action_mode_bar_stub);
            if (stub != null) {
                // Set the layout inflater so that it is inflated with the action bar's context
                stub.setLayoutInflater(LayoutInflater.from(context));
                mActionModeView = (ActionBarContextView) stub.inflate();
            }
        }
    }

    if (mActionModeView != null) {
        mActionModeView.killMode();
        ActionMode mode = new StandaloneActionMode(context, mActionModeView, wrappedCallback,
                mActionModePopup == null);
        if (callback.onCreateActionMode(mode, mode.getMenu())) {
            mode.invalidate();
            mActionModeView.initForMode(mode);
            mActionModeView.setVisibility(View.VISIBLE);
            mActionMode = mode;
            if (mActionModePopup != null) {
                mWindow.getDecorView().post(mShowActionModePopup);
            }
            mActionModeView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);

            if (mActionModeView.getParent() != null) {
                ViewCompat.requestApplyInsets((View) mActionModeView.getParent());
            }
        } else {
            mActionMode = null;
        }
    }
    if (mActionMode != null && mAppCompatCallback != null) {
        mAppCompatCallback.onSupportActionModeStarted(mActionMode);
    }
    return mActionMode;
}

From source file:cm.aptoide.pt.ManageRepos.java

private void validateRepo(final String originalUriString, final boolean editMode) {

    final ViewDisplayRepo originalRepo;

    LayoutInflater li = LayoutInflater.from(ctx);
    View view = li.inflate(R.layout.addrepo, null);

    final TextView sec_msg = (TextView) view.findViewById(R.id.sec_msg);
    final TextView sec_msg2 = (TextView) view.findViewById(R.id.sec_msg2);

    final EditText sec_user = (EditText) view.findViewById(R.id.sec_user);
    final EditText sec_pwd = (EditText) view.findViewById(R.id.sec_pwd);

    final EditText uri = (EditText) view.findViewById(R.id.edit_uri);

    final CheckBox sec = (CheckBox) view.findViewById(R.id.secure_chk);
    sec.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                sec_user.setEnabled(true);
                sec_pwd.setEnabled(true);
            } else {
                sec_user.setEnabled(false);
                sec_pwd.setEnabled(false);
            }//from w  w w.j a  v  a  2 s . co  m
        }
    });

    Builder p = new AlertDialog.Builder(theme).setView(view);
    alrt = p.create();
    CharSequence actionButtonString;
    if (editMode) {

        originalRepo = repos.getRepo(originalUriString.hashCode());
        if (originalRepo.requiresLogin()) {
            sec.setChecked(true);
            sec_user.setText(originalRepo.getLogin().getUsername());
            sec_pwd.setText(originalRepo.getLogin().getPassword());
        } else {
            sec.setChecked(false);
        }

        alrt.setIcon(R.drawable.ic_menu_edit);
        alrt.setTitle(getText(R.string.edit_repo));
        actionButtonString = getText(R.string.edit);
    } else {

        originalRepo = null;
        sec.setChecked(false);

        alrt.setIcon(R.drawable.ic_menu_add);
        alrt.setTitle(getText(R.string.add_repo));
        actionButtonString = getText(R.string.add);
    }

    alrt.setButton(actionButtonString, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            String uriString = uri.getText().toString();

            String user = null;
            String pwd = null;

            if (sec.isChecked()) {
                user = sec_user.getText().toString();
                pwd = sec_pwd.getText().toString();
            }

            Message msg = new Message();
            uriString = uriCheck(uriString);
            sec_msg.setVisibility(View.GONE);
            sec_msg2.setVisibility(View.GONE);

            returnStatus result = checkServerConnection(uriString, user, pwd);
            switch (result) {
            case OK:
                Log.d("Aptoide-ManageRepo", "return ok");
                msg.obj = 0;
                if (isRepoManaged(uriString) && ((originalRepo != null && originalRepo.requiresLogin())
                        ? (originalRepo.getLogin().getUsername().equals(user)
                                && originalRepo.getLogin().getPassword().equals(pwd))
                        : true)) {
                    Toast.makeText(ctx, "Repo " + uriString + " already exists.", 5000).show();
                    //                     finish();
                } else {
                    ViewRepository newRepo = new ViewRepository(uriString);
                    if (isRepoManaged(uriString)) {
                        if (user != null && pwd != null) {
                            reposManager.removeLogin(newRepo.getHashid());
                        } else {
                            newRepo.setLogin(new ViewLogin(user, pwd));
                            reposManager.updateLogin(newRepo);
                        }
                    } else {
                        if (user != null && pwd != null) {
                            newRepo.setLogin(new ViewLogin(user, pwd));
                        }
                        if (originalUriString != null) {
                            removeDisplayRepo(originalUriString.hashCode());
                        }
                        addDisplayRepo(newRepo);
                        refreshReposList();
                    }

                    alrt.dismiss();
                }
                break;

            case LOGIN_REQUIRED:
                Log.d("Aptoide-ManageRepo", "return login_required");
                sec_msg2.setText(getText(R.string.login_required));
                sec_msg2.setVisibility(View.VISIBLE);
                msg.obj = 1;

                break;

            case BAD_LOGIN:
                Log.d("Aptoide-ManageRepo", "return bad_login");
                sec_msg2.setText(getText(R.string.bad_login));
                sec_msg2.setVisibility(View.VISIBLE);
                msg.obj = 1;
                break;

            case FAIL:
                Log.d("Aptoide-ManageRepo", "return fail");
                uriString = uriString.substring(0, uriString.length() - 1) + ".bazaarandroid.com/";
                Log.d("Aptoide-ManageRepo", "repo uri: " + uriString);
                msg.obj = 1;
                break;

            default:
                Log.d("Aptoide-ManageRepo", "return exception");
                uriString = uriString.substring(0, uriString.length() - 1) + ".bazaarandroid.com/";
                Log.d("Aptoide-ManageRepo", "repo uri: " + uriString);
                msg.obj = 1;
                break;
            }
            if (result.equals(returnStatus.FAIL) || result.equals(returnStatus.EXCEPTION)) {
                returnStatus result2 = checkServerConnection(uriString, user, pwd);
                switch (result2) {
                case OK:
                    Log.d("Aptoide-ManageRepo", "return ok");
                    msg.obj = 0;
                    if (isRepoManaged(uriString) && ((originalRepo != null && originalRepo.requiresLogin())
                            ? (originalRepo.getLogin().getUsername().equals(user)
                                    && originalRepo.getLogin().getPassword().equals(pwd))
                            : true)) {
                        Toast.makeText(ctx, "Repo " + uriString + " already exists.", 5000).show();
                        //                        finish();
                    } else {
                        ViewRepository newRepo = new ViewRepository(uriString);
                        if (isRepoManaged(uriString)) {
                            if (user != null && pwd != null) {
                                reposManager.removeLogin(newRepo.getHashid());
                            } else {
                                newRepo.setLogin(new ViewLogin(user, pwd));
                                reposManager.updateLogin(newRepo);
                            }
                        } else {
                            if (user != null && pwd != null) {
                                newRepo.setLogin(new ViewLogin(user, pwd));
                            }
                            if (originalUriString != null) {
                                removeDisplayRepo(originalUriString.hashCode());
                            }
                            addDisplayRepo(newRepo);
                            refreshReposList();
                        }

                        alrt.dismiss();
                    }
                    break;

                case LOGIN_REQUIRED:
                    Log.d("Aptoide-ManageRepo", "return login_required");
                    sec_msg2.setText(getText(R.string.login_required));
                    sec_msg2.setVisibility(View.VISIBLE);
                    msg.obj = 1;

                    break;

                case BAD_LOGIN:
                    Log.d("Aptoide-ManageRepo", "return bad_login");
                    sec_msg2.setText(getText(R.string.bad_login));
                    sec_msg2.setVisibility(View.VISIBLE);
                    msg.obj = 1;
                    break;

                case FAIL:
                    Log.d("Aptoide-ManageRepo", "return fail");
                    sec_msg.setText(getText(R.string.cant_connect));
                    sec_msg.setVisibility(View.VISIBLE);
                    msg.obj = 1;

                    break;

                default:
                    Log.d("Aptoide-ManageRepo", "return exception");
                    msg.obj = 1;
                    break;
                }
            }
            invalidRepo.sendMessage(msg);
        }
    });

    alrt.setButton2(getText(R.string.cancel), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            alrt.dismiss();
        }
    });
    alrt.show();
    if (originalUriString != null) {
        uri.setText(originalUriString);
    }
}

From source file:com.owncloud.android.ui.activity.FileDisplayActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    boolean retval = true;
    switch (item.getItemId()) {
    case R.id.action_create_dir: {
        EditNameDialog dialog = EditNameDialog.newInstance(getString(R.string.uploader_info_dirname), "", -1,
                -1, this);
        dialog.show(getSupportFragmentManager(), "createdirdialog");
        break;//from w w  w .  j a va2 s.c o m
    }
    case R.id.action_sync_account: {
        startSynchronization();
        break;
    }
    case R.id.action_upload: {
        showDialog(DIALOG_CHOOSE_UPLOAD_SOURCE);
        break;
    }
    case R.id.action_settings: {
        Intent settingsIntent = new Intent(this, Preferences.class);
        startActivity(settingsIntent);
        break;
    }
    case R.id.action_create_file: {
        final String currentDir = getCurrentDir().getRemotePath();
        if (!currentDir.contains("Shared")) {
            AlertDialog.Builder alert = new AlertDialog.Builder(this);
            alert.setTitle("Create new file ");
            alert.setMessage("Please enter the name of the file ");

            LayoutInflater factor = LayoutInflater.from(getApplicationContext());
            final View deleteDialogView = factor.inflate(R.layout.enter_filename_dialog, null);
            alert.setView(deleteDialogView);
            final EditText edittext = (EditText) deleteDialogView.findViewById(R.id.filename);

            //Log.d(TAG, getCurrentDir().getRemotePath());
            alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    value = edittext.getText().toString();
                    Account account = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext());

                    // Log.d(TAG, "you entre "+str+" "+value);
                    int flag = 0;
                    String[] fspl = value.toString().split("\\.");
                    String taskInput;
                    if (fspl.length == 1) {
                        value = value + ".txt";
                    } else if (!fspl[fspl.length - 1].equals("txt")) {
                        value = value + ".txt";
                    }
                    uri = "file:///sdcard/ownCloud/" + account.name + currentDir + value;
                    final File f2 = new File(Environment.getExternalStorageDirectory(),
                            "ownCloud/" + account.name + currentDir);
                    final File f1 = new File(Environment.getExternalStorageDirectory(),
                            "ownCloud/" + account.name + currentDir + value);
                    try {
                        if (!f2.exists()) {
                            f2.mkdirs();
                        }
                        if (f1.createNewFile()) {
                            Intent intent = new Intent(Intent.ACTION_EDIT);
                            intent.setDataAndType(Uri.parse(uri), "text/plain");
                            startActivity(intent);
                            flag = 1;
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    } finally {
                        if (flag == 1) {
                            taskInput = f1.getAbsolutePath() + "#" + currentDir + value;
                            new displayFileTask(taskInput).execute();
                        }
                    }
                }
            });
            alert.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {

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

                }
            });
            alert.show();
        } else {
            Toast.makeText(getApplicationContext(), "You cannot create files here ", Toast.LENGTH_SHORT).show();
        }

        break;
    }
    case R.id.action_friend: {
        Intent friendsIntent = new Intent(this, TabLayoutActivity.class);
        startActivity(friendsIntent);
        break;
    }

    case R.id.action_group: {
        Intent groupIntent = new Intent(this, GroupActivity.class);
        startActivity(groupIntent);
    }
        break;
    case android.R.id.home: {
        FileFragment second = getSecondFragment();
        OCFile currentDir = getCurrentDir();
        if ((currentDir != null && currentDir.getParentId() != 0)
                || (second != null && second.getFile() != null)) {
            onBackPressed();
        }
        break;
    }
    default:
        retval = super.onOptionsItemSelected(item);
    }
    return retval;
}

From source file:com.azita.iot.ioclient.activity.MainActivity.java

public void showDialog_lightingbar(View view) {
    View dialogView = LayoutInflater.from(this).inflate(R.layout.share_bottom_dialog_lightingbar, null);
    final ShareBottomPopupDialog shareBottomPopupDialog = new ShareBottomPopupDialog(this, dialogView);
    shareBottomPopupDialog.showPopup(all_layout);

    ImageButton lightingbar_1_btn = (ImageButton) dialogView.findViewById(R.id.lightingbar_1_btn);
    lightingbar_1_btn.setOnClickListener(new View.OnClickListener() {
        @Override//from www  . j  ava  2  s . co m
        public void onClick(View view) {
            if (Lightingbar_1_btn_flag == 1) {
                Toast.makeText(MainActivity.this, "Light #1 Off", Toast.LENGTH_SHORT).show();
                if (Lightingbar_1_btn_flag == 1 && Lightingbar_2_btn_flag == 0 && Lightingbar_3_btn_flag == 0
                        && Lightingbar_4_btn_flag == 0) {

                }
                Lightingbar_1_btn_flag = 0;
            } else {
                Toast.makeText(MainActivity.this, "Light #1 On", Toast.LENGTH_SHORT).show();
                Lightingbar_1_btn_flag = 1;
            }
            _Lightingbar_1_btn = 1;
            String dummy = "{\"customerID\":2110, \"classID\":1011, \"typeID\":1001, \"DeviceID\":1001, \"value\":\"0000"
                    + Integer.toString(_Lightingdimmer_4_value * Lightingbar_4_btn_flag, 16)
                    + Integer.toString(_Lightingdimmer_3_value * Lightingbar_3_btn_flag, 16)
                    + Integer.toString(_Lightingdimmer_2_value * Lightingbar_2_btn_flag, 16)
                    + Integer.toString(_Lightingdimmer_1_value * Lightingbar_1_btn_flag, 16) + "B\"}";
            MQTTHelper_.getInstance_(mContext).publish(dummy, true);
            shareBottomPopupDialog.dismiss();
        }
    });
    if (_Lightingbar_1_btn == 1) {
        if (Lightingbar_1_btn_flag == 1) {
            lightingbar_1_btn.setImageResource(R.mipmap.opt_lighting_1);
        } else {
            lightingbar_1_btn.setImageResource(R.mipmap.opt_lighting_0);
        }
    }
    ImageButton lightingbar_2_btn = (ImageButton) dialogView.findViewById(R.id.lightingbar_2_btn);
    lightingbar_2_btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (Lightingbar_2_btn_flag == 1) {
                Toast.makeText(MainActivity.this, "Light #2 Off", Toast.LENGTH_SHORT).show();
                if (Lightingbar_1_btn_flag == 0 && Lightingbar_2_btn_flag == 1 && Lightingbar_3_btn_flag == 0
                        && Lightingbar_4_btn_flag == 0) {

                }
                Lightingbar_2_btn_flag = 0;
            } else {
                Toast.makeText(MainActivity.this, "Light #2 On", Toast.LENGTH_SHORT).show();
                Lightingbar_2_btn_flag = 1;
            }
            _Lightingbar_2_btn = 1;
            String dummy = "{\"customerID\":2110, \"classID\":1011, \"typeID\":1001, \"DeviceID\":1001, \"value\":\"0000"
                    + Integer.toString(_Lightingdimmer_4_value * Lightingbar_4_btn_flag, 16)
                    + Integer.toString(_Lightingdimmer_3_value * Lightingbar_3_btn_flag, 16)
                    + Integer.toString(_Lightingdimmer_2_value * Lightingbar_2_btn_flag, 16)
                    + Integer.toString(_Lightingdimmer_1_value * Lightingbar_1_btn_flag, 16) + "B\"}";
            MQTTHelper_.getInstance_(mContext).publish(dummy, true);
            shareBottomPopupDialog.dismiss();
        }
    });
    if (_Lightingbar_2_btn == 1) {
        if (Lightingbar_2_btn_flag == 1) {
            lightingbar_2_btn.setImageResource(R.mipmap.opt_lighting_1);
        } else {
            lightingbar_2_btn.setImageResource(R.mipmap.opt_lighting_0);
        }
    }
    ImageButton lightingbar_3_btn = (ImageButton) dialogView.findViewById(R.id.lightingbar_3_btn);
    lightingbar_3_btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (Lightingbar_3_btn_flag == 1) {
                Toast.makeText(MainActivity.this, "Light #3 Off", Toast.LENGTH_SHORT).show();
                if (Lightingbar_1_btn_flag == 0 && Lightingbar_2_btn_flag == 0 && Lightingbar_3_btn_flag == 1
                        && Lightingbar_4_btn_flag == 0) {

                }
                Lightingbar_3_btn_flag = 0;
            } else {
                Toast.makeText(MainActivity.this, "Light #3 On", Toast.LENGTH_SHORT).show();
                Lightingbar_3_btn_flag = 1;
            }
            _Lightingbar_3_btn = 1;
            String dummy = "{\"customerID\":2110, \"classID\":1011, \"typeID\":1001, \"DeviceID\":1001, \"value\":\"0000"
                    + Integer.toString(_Lightingdimmer_4_value * Lightingbar_4_btn_flag, 16)
                    + Integer.toString(_Lightingdimmer_3_value * Lightingbar_3_btn_flag, 16)
                    + Integer.toString(_Lightingdimmer_2_value * Lightingbar_2_btn_flag, 16)
                    + Integer.toString(_Lightingdimmer_1_value * Lightingbar_1_btn_flag, 16) + "B\"}";
            MQTTHelper_.getInstance_(mContext).publish(dummy, true);
            shareBottomPopupDialog.dismiss();
        }
    });
    if (_Lightingbar_3_btn == 1) {
        if (Lightingbar_3_btn_flag == 1) {
            lightingbar_3_btn.setImageResource(R.mipmap.opt_lighting_1);
        } else {
            lightingbar_3_btn.setImageResource(R.mipmap.opt_lighting_0);
        }
    }
    ImageButton lightingbar_4_btn = (ImageButton) dialogView.findViewById(R.id.lightingbar_4_btn);
    lightingbar_4_btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (Lightingbar_4_btn_flag == 1) {
                Toast.makeText(MainActivity.this, "Light #4 Off", Toast.LENGTH_SHORT).show();
                if (Lightingbar_1_btn_flag == 0 && Lightingbar_2_btn_flag == 0 && Lightingbar_3_btn_flag == 0
                        && Lightingbar_4_btn_flag == 1) {

                }
                Lightingbar_4_btn_flag = 0;
            } else {
                Toast.makeText(MainActivity.this, "Light #4 On", Toast.LENGTH_SHORT).show();
                Lightingbar_4_btn_flag = 1;
            }
            _Lightingbar_4_btn = 1;
            String dummy = "{\"customerID\":2110, \"classID\":1011, \"typeID\":1001, \"DeviceID\":1001, \"value\":\"0000"
                    + Integer.toString(_Lightingdimmer_4_value * Lightingbar_4_btn_flag, 16)
                    + Integer.toString(_Lightingdimmer_3_value * Lightingbar_3_btn_flag, 16)
                    + Integer.toString(_Lightingdimmer_2_value * Lightingbar_2_btn_flag, 16)
                    + Integer.toString(_Lightingdimmer_1_value * Lightingbar_1_btn_flag, 16) + "B\"}";
            MQTTHelper_.getInstance_(mContext).publish(dummy, true);
            shareBottomPopupDialog.dismiss();
        }
    });
    if (_Lightingbar_4_btn == 1) {
        if (Lightingbar_4_btn_flag == 1) {
            lightingbar_4_btn.setImageResource(R.mipmap.opt_lighting_1);
        } else {
            lightingbar_4_btn.setImageResource(R.mipmap.opt_lighting_0);
        }
    }
    Button share_pop_cancle_btn = (Button) dialogView.findViewById(R.id.share_pop_cancle_btn);
    share_pop_cancle_btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            shareBottomPopupDialog.dismiss();
        }
    });
}

From source file:pt.aptoide.backupapps.ManageRepos.java

private void validateRepo(final String originalUriString, final boolean editMode) {

    final ViewDisplayRepo originalRepo;

    LayoutInflater li = LayoutInflater.from(ctx);
    View view = li.inflate(R.layout.addrepo, null);

    final TextView sec_msg = (TextView) view.findViewById(R.id.sec_msg);
    final TextView sec_msg2 = (TextView) view.findViewById(R.id.sec_msg2);

    final EditText sec_user = (EditText) view.findViewById(R.id.sec_user);
    final EditText sec_pwd = (EditText) view.findViewById(R.id.sec_pwd);

    final EditText uri = (EditText) view.findViewById(R.id.edit_uri);

    final CheckBox sec = (CheckBox) view.findViewById(R.id.secure_chk);
    sec.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                sec_user.setEnabled(true);
                sec_pwd.setEnabled(true);
            } else {
                sec_user.setEnabled(false);
                sec_pwd.setEnabled(false);
            }/*ww w.j a v a 2  s  . co  m*/
        }
    });

    Builder p = new AlertDialog.Builder(theme).setView(view);
    alrt = p.create();
    CharSequence actionButtonString;
    if (editMode) {

        originalRepo = repos.getRepo(originalUriString.hashCode());
        if (originalRepo.requiresLogin()) {
            sec.setChecked(true);
            sec_user.setText(originalRepo.getLogin().getUsername());
            sec_pwd.setText(originalRepo.getLogin().getPassword());
        } else {
            sec.setChecked(false);
        }

        alrt.setIcon(R.drawable.ic_menu_edit);
        alrt.setTitle(getText(R.string.edit_repo));
        actionButtonString = getText(R.string.edit);
    } else {

        originalRepo = null;
        sec.setChecked(false);

        alrt.setIcon(R.drawable.ic_menu_add);
        alrt.setTitle(getText(R.string.add_repo));
        actionButtonString = getText(R.string.add);
    }

    alrt.setButton(actionButtonString, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            String uriString = uri.getText().toString();

            String user = null;
            String pwd = null;

            if (sec.isChecked()) {
                user = sec_user.getText().toString();
                pwd = sec_pwd.getText().toString();
            }

            Message msg = new Message();
            uriString = uriCheck(uriString);
            sec_msg.setVisibility(View.GONE);
            sec_msg2.setVisibility(View.GONE);

            returnStatus result = checkServerConnection(uriString, user, pwd);
            switch (result) {
            case OK:
                Log.d("Aptoide-ManageRepo", "return ok");
                msg.obj = 0;
                if (isRepoManaged(uriString) && ((originalRepo != null && originalRepo.requiresLogin())
                        ? (originalRepo.getLogin().getUsername().equals(user)
                                && originalRepo.getLogin().getPassword().equals(pwd))
                        : true)) {
                    Toast.makeText(ctx, "Repo " + uriString + " already exists.", 5000).show();
                    //                     finish();
                } else {
                    ViewRepository newRepo = new ViewRepository(uriString);
                    if (isRepoManaged(uriString)) {
                        if (user != null && pwd != null) {
                            reposManager.removeLogin(newRepo.getHashid());
                        } else {
                            newRepo.setLogin(new ViewLogin(user, pwd));
                            reposManager.updateLogin(newRepo);
                        }
                    } else {
                        if (user != null && pwd != null) {
                            newRepo.setLogin(new ViewLogin(user, pwd));
                        }
                        if (originalUriString != null) {
                            removeDisplayRepo(originalUriString.hashCode());
                        }
                        addDisplayRepo(newRepo);
                        refreshReposList();
                    }

                    alrt.dismiss();
                }
                break;

            case LOGIN_REQUIRED:
                Log.d("Aptoide-ManageRepo", "return login_required");
                sec_msg2.setText(getText(R.string.login_required));
                sec_msg2.setVisibility(View.VISIBLE);
                msg.obj = 1;

                break;

            case BAD_LOGIN:
                Log.d("Aptoide-ManageRepo", "return bad_login");
                sec_msg2.setText(getText(R.string.check_login));
                sec_msg2.setVisibility(View.VISIBLE);
                msg.obj = 1;
                break;

            case FAIL:
                Log.d("Aptoide-ManageRepo", "return fail");
                uriString = uriString.substring(0, uriString.length() - 1) + Constants.DOMAIN_APTOIDE_STORE;
                Log.d("Aptoide-ManageRepo", "repo uri: " + uriString);
                msg.obj = 1;
                break;

            default:
                Log.d("Aptoide-ManageRepo", "return exception");
                uriString = uriString.substring(0, uriString.length() - 1) + Constants.DOMAIN_APTOIDE_STORE;
                Log.d("Aptoide-ManageRepo", "repo uri: " + uriString);
                msg.obj = 1;
                break;
            }
            if (result.equals(returnStatus.FAIL) || result.equals(returnStatus.EXCEPTION)) {
                returnStatus result2 = checkServerConnection(uriString, user, pwd);
                switch (result2) {
                case OK:
                    Log.d("Aptoide-ManageRepo", "return ok");
                    msg.obj = 0;
                    if (isRepoManaged(uriString) && ((originalRepo != null && originalRepo.requiresLogin())
                            ? (originalRepo.getLogin().getUsername().equals(user)
                                    && originalRepo.getLogin().getPassword().equals(pwd))
                            : true)) {
                        Toast.makeText(ctx, "Repo " + uriString + " already exists.", 5000).show();
                        //                        finish();
                    } else {
                        ViewRepository newRepo = new ViewRepository(uriString);
                        if (isRepoManaged(uriString)) {
                            if (user != null && pwd != null) {
                                reposManager.removeLogin(newRepo.getHashid());
                            } else {
                                newRepo.setLogin(new ViewLogin(user, pwd));
                                reposManager.updateLogin(newRepo);
                            }
                        } else {
                            if (user != null && pwd != null) {
                                newRepo.setLogin(new ViewLogin(user, pwd));
                            }
                            if (originalUriString != null) {
                                removeDisplayRepo(originalUriString.hashCode());
                            }
                            addDisplayRepo(newRepo);
                            refreshReposList();
                        }

                        alrt.dismiss();
                    }
                    break;

                case LOGIN_REQUIRED:
                    Log.d("Aptoide-ManageRepo", "return login_required");
                    sec_msg2.setText(getText(R.string.login_required));
                    sec_msg2.setVisibility(View.VISIBLE);
                    msg.obj = 1;

                    break;

                case BAD_LOGIN:
                    Log.d("Aptoide-ManageRepo", "return bad_login");
                    sec_msg2.setText(getText(R.string.check_login));
                    sec_msg2.setVisibility(View.VISIBLE);
                    msg.obj = 1;
                    break;

                case FAIL:
                    Log.d("Aptoide-ManageRepo", "return fail");
                    sec_msg.setText(getText(R.string.cant_connect));
                    sec_msg.setVisibility(View.VISIBLE);
                    msg.obj = 1;

                    break;

                default:
                    Log.d("Aptoide-ManageRepo", "return exception");
                    msg.obj = 1;
                    break;
                }
            }
            invalidRepo.sendMessage(msg);
        }
    });

    alrt.setButton2(getText(R.string.cancel), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            alrt.dismiss();
        }
    });
    alrt.show();
    if (originalUriString != null) {
        uri.setText(originalUriString);
    }
}

From source file:android.support.v17.leanback.widget.GuidedActionsStylist.java

/**
 * Constructs a {@link ViewHolder} capable of representing {@link GuidedAction}s. Subclasses
 * may choose to return a subclass of ViewHolder.  To support different view types, override
 * {@link #onCreateViewHolder(ViewGroup, int)}
 * <p>//  ww  w  .  j  ava2 s. c  o  m
 * <i>Note: Should not actually add the created view to the parent; the caller will do
 * this.</i>
 * @param parent The view group to be used as the parent of the new view.
 * @return The view to be added to the caller's view hierarchy.
 */
public ViewHolder onCreateViewHolder(ViewGroup parent) {
    LayoutInflater inflater = LayoutInflater.from(parent.getContext());
    View v = inflater.inflate(onProvideItemLayoutId(), parent, false);
    return new ViewHolder(v, parent == mSubActionsGridView);
}

From source file:android.support.v17.leanback.widget.GuidedActionsStylist.java

/**
 * Constructs a {@link ViewHolder} capable of representing {@link GuidedAction}s. Subclasses
 * may choose to return a subclass of ViewHolder.
 * <p>/*from ww w  . j a va  2 s . c  o  m*/
 * <i>Note: Should not actually add the created view to the parent; the caller will do
 * this.</i>
 * @param parent The view group to be used as the parent of the new view.
 * @param viewType The viewType returned by {@link #getItemViewType(GuidedAction)}
 * @return The view to be added to the caller's view hierarchy.
 */
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    if (viewType == VIEW_TYPE_DEFAULT) {
        return onCreateViewHolder(parent);
    }
    LayoutInflater inflater = LayoutInflater.from(parent.getContext());
    View v = inflater.inflate(onProvideItemLayoutId(viewType), parent, false);
    return new ViewHolder(v, parent == mSubActionsGridView);
}

From source file:com.insthub.O2OMobile.Activity.C1_PublishOrderActivity.java

public void initData() {
    Date date = new Date();
    mTime.setText(mFormat.format(date));
    mTime.setOnClickListener(new OnClickListener() {

        @Override/*from w  ww. ja v a2s  .c o  m*/
        public void onClick(View v) {
            // TODO Auto-generated method stub
            closeKeyBoard();
            LayoutInflater inflater = LayoutInflater.from(C1_PublishOrderActivity.this);
            final View timepickerview = inflater.inflate(R.layout.timepicker, null);
            ScreenInfo screenInfo = new ScreenInfo(C1_PublishOrderActivity.this);
            mWheelMain = new WheelMain(timepickerview, true);
            mWheelMain.screenheight = screenInfo.getHeight();
            Calendar calendar = Calendar.getInstance();
            try {
                calendar.setTime(mFormat.parse(mTime.getText().toString()));
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            int year = calendar.get(Calendar.YEAR);
            int month = calendar.get(Calendar.MONTH);
            int day = calendar.get(Calendar.DAY_OF_MONTH);
            int hour = calendar.get(Calendar.HOUR_OF_DAY);
            int min = calendar.get(Calendar.MINUTE);
            mWheelMain.initDateTimePicker(year, month, day, hour, min);
            new AlertDialog.Builder(C1_PublishOrderActivity.this).setTitle(getString(R.string.choose_time))
                    .setView(timepickerview)
                    .setPositiveButton(getString(R.string.confirm), new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            mTime.setText(mWheelMain.getTime());
                        }
                    }).setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                        }
                    }).show();
        }
    });
}

From source file:edu.cens.loci.ui.PlaceViewActivity.java

@Override
protected Dialog onCreateDialog(int id, Bundle args) {
    LayoutInflater factory = LayoutInflater.from(this);

    switch (id) {
    case DIALOG_WIFI:
        final View wifiView = factory.inflate(R.layout.dialog_wifi_view, null);
        final TableLayout wifiTable = (TableLayout) wifiView.findViewById(R.id.wifi_table);
        //updateWifiList(wifiTable, mPlace.wifis.get(0));
        String wifiJson = args.getString("wifi");
        //Log.d(TAG, "createDialog: " + wifiJson);
        try {//  w  w  w. j  av a2s  . c o m
            updateWifiList(wifiTable, new LociWifiFingerprint(wifiJson));
        } catch (JSONException e) {
            MyLog.e(LociConfig.D.JSON, TAG, "updateWifiList: json failed.");
            e.printStackTrace();
            return null;
        }
        return new AlertDialog.Builder(this).setIcon(R.drawable.ic_settings_wireless)
                .setTitle("Nearby Wi-Fi Access Points").setView(wifiView)
                .setPositiveButton("Close", new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub

                    }
                }).create();
    case DIALOG_VISITS:
        return new AlertDialog.Builder(this).setIcon(R.drawable.ic_clock_strip_desk_clock)
                .setTitle("Recent visits").setItems(getAllVisits(), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {

                    }
                }).setPositiveButton("Close", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {

                    }
                }).create();
    case DIALOG_CONFIRM_DELETE:
        return new AlertDialog.Builder(this).setIcon(R.drawable.ic_menu_delete).setTitle("Are you sure?")
                .setPositiveButton("Delete", new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        //mDbUtils.updatePlaceState(mPlaceId, Places.STATE_DELETED);

                        MyLog.d(LociConfig.D.UI.DEBUG, TAG, "[delete] before");
                        mDbUtils.checkPlaceTable();
                        mDbUtils.checkDataTable();
                        mDbUtils.deletePlace(mPlaceId);
                        MyLog.d(LociConfig.D.UI.DEBUG, TAG, "[delete] after");
                        mDbUtils.checkPlaceTable();
                        mDbUtils.checkDataTable();
                        finish();
                    }
                }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {

                    }
                }).create();
    case DIALOG_CONFIRM_BLOCK:
        return new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_menu_close_clear_cancel)
                .setTitle("Are you sure?").setMessage("Visits to a blocked place will not be recognized.")
                .setPositiveButton("Block", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        mDbUtils.updatePlaceState(mPlaceId, Places.STATE_BLOCKED);
                        finish();
                    }
                }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                    }
                }).create();
    case DIALOG_CONFIRM_UNBLOCK:
        return new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_menu_close_clear_cancel)
                .setTitle("Are you sure?").setPositiveButton("Unblock", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        mDbUtils.updatePlaceState(mPlaceId, Places.STATE_REGISTERED);
                        finish();
                    }
                }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                    }
                }).create();
    }
    return null;
}

From source file:apps.junkuvo.alertapptowalksafely.MainActivity.java

public void setStartButtonFunction(final View v) {
    DefaultLayoutPromptView promptView = (DefaultLayoutPromptView) findViewById(R.id.prompt_view);
    promptView.setVisibility(View.GONE);

    if (mAlertService.IsRunningAlertService()) {
        FlurryAgent.logEvent("Service Stop!!");
        Bundle bundle = new Bundle();
        bundle.putString(FirebaseAnalytics.Param.END_DATE,
                DateUtil.getNowDate(DateUtil.DATE_FORMAT.YYYYMMDDhhmmss));
        mFirebaseAnalytics.logEvent("service_stop", bundle);

        mStepCount = mAlertService.getStepCountCurrent();
        changeViewState(false, ((ActionButton) v));
        Toast.makeText(this, getString(R.string.app_used_thankyou), Toast.LENGTH_SHORT).show();

        // 0?????????????Insert
        if (mStepCount > 0 && enableNewFunction) {
            RealmUtil.insertHistoryItemAsync(realm, createHistoryItemData(),
                    new RealmUtil.realmTransactionCallbackListener() {
                        @Override
                        public void OnSuccess() {

                        }/*from w ww.j  a v a  2  s  .  c  om*/

                        @Override
                        public void OnError() {

                        }
                    });
        }

        // ? ?? Twitter????
        if (TwitterUtility.hasAccessToken(getApplicationContext()) && enableNewFunction) {
            Context context = MainActivity.this;
            LayoutInflater inflater = LayoutInflater.from(context);
            View layout = inflater.inflate(R.layout.sharetotwitter,
                    (ViewGroup) findViewById(R.id.layout_root_twitter));
            mAlertDialog = new AlertDialog.Builder(context);
            String timeStamp = new SimpleDateFormat(DateUtil.DATE_FORMAT.YYYYMMDD_HHmmss.getFormat())
                    .format(Calendar.getInstance().getTime());
            mAlertDialog.setTitle(context.getString(R.string.dialog_tweet));
            mAlertDialog.setIcon(R.drawable.ic_share_black_48dp);
            mAlertDialog.setView(layout);
            mTweetText = (EditText) layout.findViewById(R.id.edtTweet);
            mTweetText.setText(String.valueOf(mStepCount) + getString(R.string.twitter_tweet_step) + "\n"
                    + getString(R.string.twitter_tweetText) + "\n"
                    + String.format(getString(R.string.app_googlePlay_url), getPackageName()) + "\n"
                    + timeStamp);
            mAlertDialog.setPositiveButton(context.getString(R.string.dialog_button_send),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            tweet(mTweetText.getText().toString());
                        }
                    });
            mAlertDialog.setCancelable(false);
            mAlertDialog.setNegativeButton(context.getString(R.string.dialog_button_cancel), null);
            mAlertDialog.show();
        }

        mAlertService.stopSensors();

        // 
        if (!enableNewFunction) {
            LayoutInflater inflater = LayoutInflater.from(this);
            final View layout = inflater.inflate(R.layout.ad_dialog,
                    (ViewGroup) findViewById(R.id.layout_root_ad));
            new MaterialStyledDialog(this).setTitle("????????")
                    .setDescription("?????????????")
                    .setCustomView(layout).setIcon(R.drawable.ic_new_releases_white_48dp)
                    .setHeaderDrawable(R.drawable.pattern_bg_blue).setCancelable(false)
                    .setPositive(getString(R.string.ok), new MaterialDialog.SingleButtonCallback() {
                        @Override
                        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                            displayInterstitial();
                        }
                    }).show();
        }

        mbtnStart.setShowAnimation(ActionButton.Animations.SCALE_UP);
        mbtnStart.playShowAnimation();

    } else {
        if (mStepCount > 0) {
            mAlertDialog = new AlertDialog.Builder(MainActivity.this);
            mAlertDialog.setIcon(R.drawable.ic_stat_small);
            mAlertDialog.setMessage("0?????????");
            mAlertDialog.setPositiveButton("0??", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String initial = getString(R.string.zero) + getString(R.string.home_step_count_dimension);
                    ((TextView) findViewById(R.id.txtStepCount)).setText(initial);
                    ((TextView) findViewById(R.id.txtStepNo)).setText(initial);
                    start(v);
                }
            });
            mAlertDialog.setNeutralButton("???", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    shouldContinue = true;
                    start(v);
                }
            });
            mAlertDialog.setNegativeButton("???", null);
            mAlertDialog.show();
        } else {
            start(v);
        }
    }
}