Example usage for android.media RingtoneManager EXTRA_RINGTONE_EXISTING_URI

List of usage examples for android.media RingtoneManager EXTRA_RINGTONE_EXISTING_URI

Introduction

In this page you can find the example usage for android.media RingtoneManager EXTRA_RINGTONE_EXISTING_URI.

Prototype

String EXTRA_RINGTONE_EXISTING_URI

To view the source code for android.media RingtoneManager EXTRA_RINGTONE_EXISTING_URI.

Click Source Link

Document

Given to the ringtone picker as a Uri .

Usage

From source file:rikka.materialpreference.RingtonePreference.java

/**
 * Prepares the intent to launch the ringtone picker. This can be modified
 * to adjust the parameters of the ringtone picker.
 *
 * @param ringtonePickerIntent The ringtone picker intent that can be
 *            modified by putting extras.
 *//*from  w  w w  .  java  2  s.  c o  m*/
protected void onPrepareRingtonePickerIntent(Intent ringtonePickerIntent) {

    ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, onRestoreRingtone());

    ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, mShowDefault);
    if (mShowDefault) {
        ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI,
                RingtoneManager.getDefaultUri(getRingtoneType()));
    }

    ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, mShowSilent);
    ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, mRingtoneType);
    ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, getTitle());
}

From source file:org.schabi.terminightor.AlarmItemDetailFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    lastSavedInstaneState = savedInstanceState;
    Activity a = getActivity();// w ww.  j  av a2  s  .c om
    setAlarmTimeView = (TextView) a.findViewById(R.id.setAlarmTimeView);
    setAlarmAMPMView = (TextView) a.findViewById(R.id.setAlarmAmPmSuffix);
    repeatCheckBox = (CheckBox) a.findViewById(R.id.setRepeatCheckBox);
    chooseDateView = (ChooseDaysView) a.findViewById(R.id.chooseDateView);
    alarmLabelBox = (EditText) a.findViewById(R.id.setAlarmLabelBox);
    setAlarmToneButton = (Button) a.findViewById(R.id.setAlarmToneButton);
    vibrateCheckBox = (CheckBox) a.findViewById(R.id.vibrateCheckBox);
    nfcTagLabelView = (ImageView) a.findViewById(R.id.nfcTagLabelView);
    nfcTagIdView = (TextView) a.findViewById(R.id.nfcTagIdView);
    addNfcTabButton = (FloatingActionButton) a.findViewById(R.id.addNfcTagButton);

    repeatCheckBox.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (repeatCheckBox.isChecked()) {
                chooseDateView.setVisibility(View.VISIBLE);
            } else {
                chooseDateView.setVisibility(View.GONE);
            }
            chooseDateView.setRepeatEnabled(repeatCheckBox.isChecked());
        }
    });

    setAlarmTimeView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            timePickerDialog.show();
        }
    });

    setAlarmToneButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE,
                    getResources().getString(R.string.selectAlarmToneTitle));
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_ALARM);
            if (!alarm.getAlarmTone().isEmpty()) {
                intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(alarm.getAlarmTone()));
            }
            startActivityForResult(intent, SET_ALARM_TONE);
        }
    });

    addNfcTabButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getActivity(), SetTagActivity.class);
            startActivityForResult(intent, READ_NFC_ID);
        }
    });
}

From source file:com.example.mydemos.view.RingtonePickerActivity.java

/** Called when the activity is first created. */
@Override//from  www . j  av  a  2  s  .c  o m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.ringtone_picker);
    CharSequence sysTitle = (CharSequence) getResources().getText(R.string.sys_tone);
    CharSequence MusicTitle = (CharSequence) getResources().getText(R.string.sd_music);
    CharSequence RecordTitle = (CharSequence) getResources().getText(R.string.record_tone);
    Intent intent = getIntent();
    toneType = intent.getIntExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, -1);

    Log.e("duwenhua", "ringPick get toneType:" + toneType);

    //! by duwenhua
    //if(toneType == RingtoneManager.TYPE_RINGTONE_SECOND)
    //    toneType = RINGTONE_TYPE;

    //! by duwenhua
    mHasDefaultItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
    mUriForDefaultItem = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI);
    //Log.i("lys", "mUriForDefaultItem == " + mUriForDefaultItem);
    if (savedInstanceState != null) {
        mSelectedId = savedInstanceState.getLong(SAVE_CLICKED_POS, -1);
    }
    //Log.i("lys", "mUriForDefaultItem 1== " + mUriForDefaultItem+", mSelectedId =="+mSelectedId);      
    mHasSilentItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
    mExistingUri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI);
    //if(mUriForDefaultItem != null)
    //{
    //    mSelectedId = ContentUris.parseId(mUriForDefaultItem);
    //}

    //Log.i("lys", "RingtonePickerActivity.java onCreate mExistingUri == " + mExistingUri);   
    //String action = getIntent().getAction();
    //Log.i("lys", "PT Intent action == " + action);

    if (toneType == NOTIFICATION_TYPE) {
        mUriForDefaultItem = Settings.System.DEFAULT_NOTIFICATION_URI;
    } else if (toneType == RINGTONE_TYPE) {
        mUriForDefaultItem = Settings.System.DEFAULT_RINGTONE_URI;
    } else if (toneType == ALARM_TYPE) {
        mUriForDefaultItem = Settings.System.DEFAULT_ALARM_ALERT_URI;
    }

    if (isAvailableToCheckRingtone() == true) {
        Ringtone ringtone_DefaultItem = checkRingtone_reflect(this, mUriForDefaultItem, toneType);
        if (ringtone_DefaultItem != null && ringtone_DefaultItem.getUri() != null) {
            mUriForDefaultItem = ringtone_DefaultItem.getUri();
            Log.i("lys", "RingtoneManager.getRingtone  mUriForDefaultItem== " + mUriForDefaultItem);
        } else {
            //mUriForDefaultItem = 'content/medial/';
            /*ZTE_AUDIO_LIYANG 2014/06/30 fix bug for ringtone when remove sdcard start */
            String originalRingtone = Settings.System.getString(getApplicationContext().getContentResolver(),
                    "ringtone_original");
            if (originalRingtone != null && !TextUtils.isEmpty(originalRingtone)) {
                mUriForDefaultItem = Uri.parse(originalRingtone);
                Log.e("liyang", "select riongtone error  ,change to originalRingtone == " + mExistingUri);
            }
            /*ZTE_AUDIO_LIYANG 2014/06/30 fix bug for ringtone when remove sdcard end */
            Log.i("lys", "mUriForDefaultItem set as default mUriForDefaultItem== 222");
        }

        if (mExistingUri != null) {
            Ringtone ringtone = checkRingtone_reflect(this, mExistingUri, toneType);
            if (ringtone != null && ringtone.getUri() != null) {
                //mUriForDefaultItem = ringtone.getUri(); 
                mExistingUri = ringtone.getUri();
                Log.i("lys", "RingtoneManager.getRingtone  mExistingUri== " + mExistingUri);
            } else {
                mExistingUri = mUriForDefaultItem;
                Log.i("lys", "mExistingUri set as default mExistingUri== " + mExistingUri);
            }
        }
    }

    boolean includeDrm = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_INCLUDE_DRM, false);
    Log.e("lys", "includeDrm ==" + includeDrm);
    mRingtoneManager = new RingtoneManager(this);
    mRingtoneManager.setIncludeDrm(includeDrm);
    if (toneType != -1) {
        mRingtoneManager.setType(toneType);
    }

    setVolumeControlStream(mRingtoneManager.inferStreamType());
    //   toneActivityType = mRingtoneManager.getActivityType();
    if (toneType == ALARM_TYPE) {
        sysTitle = (CharSequence) getResources().getText(R.string.alarm_tone);
    } else if (toneType == NOTIFICATION_TYPE) {
        sysTitle = (CharSequence) getResources().getText(R.string.notification_tone);
    }

    listView = new ListView(this);
    listView.setOnItemClickListener(this);
    //listView.setBackgroundColor(#ff5a5a5a);
    listView.setFastScrollEnabled(true);
    //listView.setFastScrollAlwaysVisible(true);
    listView.setEmptyView(findViewById(android.R.id.empty));
    //mHasSilentItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);

    //mHasDefaultItem = true; //temp
    if (mHasDefaultItem) {
        //chengcheng
        addDefaultStaticItem(listView, com.android.internal.R.string.ringtone_default);

    }

    setDefaultRingtone();

    if (mHasSilentItem) {
        // chengcheng
        addSilendStaticItem(listView, com.android.internal.R.string.ringtone_silent);
    }
    audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    mAudioFocusListener = new OnAudioFocusChangeListener() {
        public void onAudioFocusChange(int focusChange) {

        }
    };

    okBtn = (Button) findViewById(R.id.ok);
    okBtn.setOnClickListener(this);
    cancelBtn = (Button) findViewById(R.id.cancel);
    cancelBtn.setOnClickListener(this);

    TabHost mTabHost = (TabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup();
    mTabHost.addTab(mTabHost.newTabSpec("tab_system").setIndicator(sysTitle, null).setContent(this));
    mTabHost.addTab(mTabHost.newTabSpec("tab_music").setIndicator(MusicTitle, null).setContent(this));
    mTabHost.addTab(mTabHost.newTabSpec("tab_record").setIndicator(RecordTitle, null).setContent(this));
    mTabHost.setCurrentTab(0);
    mTabHost.setOnTabChangedListener(new OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            // stopMediaPlayer();
            createTabContent(tabId);
        }
    });
}

From source file:org.telegram.ui.ChatProfileActivity.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (fragmentView == null) {
        fragmentView = inflater.inflate(R.layout.chat_profile_layout, container, false);

        listView = (ListView) fragmentView.findViewById(R.id.listView);
        listView.setAdapter(listViewAdapter = new ListAdapter(parentActivity));
        listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override//from   www  .j a v a2  s. c  om
            public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
                int size = 0;
                if (info != null) {
                    size += info.participants.size();
                }
                if (i > 6 && i < size + 7) {
                    TLRPC.TL_chatParticipant user = info.participants.get(sortedUsers.get(i - 7));
                    if (user.user_id == UserConfig.clientUserId) {
                        return false;
                    }
                    if (info.admin_id != UserConfig.clientUserId
                            && user.inviter_id != UserConfig.clientUserId) {
                        return false;
                    }
                    selectedUser = user;

                    AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
                    CharSequence[] items = new CharSequence[] { getStringEntry(R.string.KickFromGroup) };

                    builder.setItems(items, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            if (i == 0) {
                                kickUser(selectedUser);
                            }
                        }
                    });
                    builder.show().setCanceledOnTouchOutside(true);

                    return true;
                }
                return false;
            }
        });

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                if (i == 2) {
                    SharedPreferences preferences = parentActivity.getSharedPreferences("Notifications",
                            Activity.MODE_PRIVATE);
                    String key = "notify_" + (-chat_id);
                    boolean value = preferences.getBoolean(key, true);
                    SharedPreferences.Editor editor = preferences.edit();
                    editor.putBoolean(key, !value);
                    editor.commit();
                    listView.invalidateViews();
                } else if (i == 3) {
                    try {
                        Intent tmpIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
                        tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,
                                RingtoneManager.TYPE_NOTIFICATION);
                        tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, false);
                        SharedPreferences preferences = parentActivity.getSharedPreferences("Notifications",
                                Activity.MODE_PRIVATE);
                        Uri currentSound = null;

                        String defaultPath = null;
                        Uri defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI;
                        if (defaultUri != null) {
                            defaultPath = defaultUri.getPath();
                        }

                        String path = preferences.getString("sound_chat_path_" + chat_id, defaultPath);
                        if (path != null && !path.equals("NoSound")) {
                            if (path.equals(defaultPath)) {
                                currentSound = defaultUri;
                            } else {
                                currentSound = Uri.parse(path);
                            }
                        }

                        tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currentSound);
                        startActivityForResult(tmpIntent, 15);
                    } catch (Exception e) {
                        FileLog.e("tmessages", e);
                    }
                } else if (i == 5) {
                    MediaActivity fragment = new MediaActivity();
                    Bundle bundle = new Bundle();
                    bundle.putLong("dialog_id", -chat_id);
                    fragment.setArguments(bundle);
                    ((ApplicationActivity) parentActivity).presentFragment(fragment, "media_chat_" + chat_id,
                            false);
                } else {
                    int size = 0;
                    if (info != null) {
                        size += info.participants.size();
                    }
                    if (i > 6 && i < size + 7) {
                        int user_id = info.participants.get(sortedUsers.get(i - 7)).user_id;
                        if (user_id == UserConfig.clientUserId) {
                            return;
                        }
                        UserProfileActivity fragment = new UserProfileActivity();
                        Bundle args = new Bundle();
                        args.putInt("user_id", user_id);
                        fragment.setArguments(args);
                        ((ApplicationActivity) parentActivity).presentFragment(fragment, "user_" + user_id,
                                false);
                    } else {
                        if (size + 7 == i) {
                            if (info.participants.size() < 200) {
                                openAddMenu();
                            } else {
                                kickUser(null);
                            }
                        } else if (size + 7 == i + 1) {
                            kickUser(null);
                        }
                    }
                }
            }
        });

        listView.setOnTouchListener(new OnSwipeTouchListener() {
            public void onSwipeRight() {
                finishFragment(true);
            }
        });
    } else {
        ViewGroup parent = (ViewGroup) fragmentView.getParent();
        if (parent != null) {
            parent.removeView(fragmentView);
        }
    }
    return fragmentView;
}

From source file:support.plus.reportit.SettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // Default config

    if (savedInstanceState != null) {
        // Restore value of members from saved state
        userName = savedInstanceState.getString(userName);
        userBossName = savedInstanceState.getString(userBossName);
    } else {/*w w  w .  j ava 2  s. c  o m*/
        // Probably initialize members with default values for a new instance
    }

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);

    Toolbar toolbar = (Toolbar) findViewById(R.id.settings_toolbar);
    setSupportActionBar(toolbar);
    toolbar.setTitle(R.string.app_name);
    toolbar.setNavigationIcon(R.drawable.ic_back);

    final TextView TextuserName = (TextView) findViewById(R.id.userName);
    final TextView TextuserBossName = (TextView) findViewById(R.id.userBossName);
    final EditText inuserName = (EditText) findViewById(R.id.inuserName);
    final EditText inuserBossName = (EditText) findViewById(R.id.inuserBossName);
    final Switch sNoti = (Switch) findViewById(R.id.sNoti);
    final Button btimePick = (Button) findViewById(R.id.btimePick);
    final Button bSave = (Button) findViewById(R.id.bSave);
    final Switch sfingerprint_activ = (Switch) findViewById(R.id.sfingerprint_activ);
    final Button bsetpassword = (Button) findViewById(R.id.bsetpassword);
    final Switch sdarkTheme = (Switch) findViewById(R.id.sdarkTheme);
    final Button bchooseRingtone = (Button) findViewById(R.id.bringtonePick);

    final SharedPreferences pref3 = getSharedPreferences("Theme", Context.MODE_PRIVATE);
    Boolean themeDark = pref3.getBoolean("darkTheme", false);
    if (themeDark == true) {
        sdarkTheme.setChecked(true);
    } else {
        sdarkTheme.setChecked(false);
    }
    sdarkTheme.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                final SharedPreferences pref3 = getSharedPreferences("Theme", Context.MODE_PRIVATE);
                SharedPreferences.Editor editor = pref3.edit();
                editor.putBoolean("darkTheme", true);
                editor.commit();
                getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
                // Now recreate for it to take effect
                // startActivity(getIntent());
                recreate();
            } else {
                SharedPreferences.Editor editor = pref3.edit();
                editor.putBoolean("darkTheme", false);
                editor.commit();
                getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_AUTO);
                // Now recreate for it to take effect
                // startActivity(getIntent());
                recreate();
            }
        }
    });

    /*
    SECURITY SETTINGS
     */

    final SharedPreferences pref1 = getSharedPreferences("Fingerprint", Context.MODE_PRIVATE);
    Boolean fingerprintSet = pref1.getBoolean("fingerprintSet", false);
    if (fingerprintSet == true) {
        sfingerprint_activ.setChecked(true);
        bsetpassword.setVisibility(View.VISIBLE);
    } else {
        sfingerprint_activ.setChecked(false);
        bsetpassword.setVisibility(View.GONE);
    }
    sfingerprint_activ.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                SharedPreferences.Editor editor = pref1.edit();
                editor.putBoolean("fingerprintSet", true);
                editor.commit();
                bsetpassword.setVisibility(View.VISIBLE);
            } else {
                SharedPreferences.Editor editor = pref1.edit();
                editor.putBoolean("fingerprintSet", false);
                editor.commit();
                bsetpassword.setVisibility(View.GONE);
            }
        }
    });

    bsetpassword.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new MaterialDialog.Builder(SettingsActivity.this).title(R.string.set_password)
                    .content(R.string.set_password_desc)
                    .inputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD)
                    .inputRange(1, 10)
                    .input(getString(R.string.password), "", new MaterialDialog.InputCallback() {
                        @Override
                        public void onInput(MaterialDialog dialog, CharSequence input) {
                            String name = String.valueOf(input);
                            SharedPreferences pref1 = getSharedPreferences("Fingerprint", Context.MODE_PRIVATE);
                            SharedPreferences.Editor editor = pref1.edit();
                            editor.putString("passwordSet", name);
                            editor.commit();
                            return;
                        }
                    }).positiveText(R.string.set_password).negativeText(R.string.cancel).cancelable(false)
                    .show();
        }

    });

    /*
    END SECURITY SETTINGS
     */

    /*
    NOTIFICATION SETTINGS
     */
    btimePick.setVisibility(View.GONE);
    sNoti.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                btimePick.setVisibility(View.VISIBLE);
                bchooseRingtone.setVisibility(View.VISIBLE);
            } else {
                btimePick.setVisibility(View.GONE);
                bchooseRingtone.setVisibility(View.GONE);
            }
        }
    });

    final SharedPreferences pref4 = getApplicationContext().getSharedPreferences("userNotification",
            MODE_PRIVATE);
    Boolean notificationSet = pref4.getBoolean("alarmSet", false);
    if (notificationSet == true) {
        sNoti.setChecked(true);
        btimePick.setVisibility(View.VISIBLE);
        bchooseRingtone.setVisibility(View.VISIBLE);
    } else {
        sNoti.setChecked(false);
        btimePick.setVisibility(View.GONE);
        bchooseRingtone.setVisibility(View.GONE);
    }
    sNoti.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                SharedPreferences.Editor editor = pref4.edit();
                editor.putBoolean("alarmSet", true);
                editor.commit();
                btimePick.setVisibility(View.VISIBLE);
                bchooseRingtone.setVisibility(View.VISIBLE);

            } else {
                SharedPreferences.Editor editor = pref4.edit();
                editor.putBoolean("alarmSet", false);
                editor.commit();
                btimePick.setVisibility(View.GONE);
                bchooseRingtone.setVisibility(View.GONE);

            }
        }
    });
    bchooseRingtone.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, R.string.choose_ringtone);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) null);
            startActivityForResult(intent, 5);
        }
    });

    btimePick.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            DialogFragment newFragment = new TimePickerFragment();
            newFragment.show(getSupportFragmentManager(), "timePicker");
        }
    });

    /*
    END NOTIFICATION SETTINGS
     */

    /*
    SAVE SETTINGS
     */
    bSave.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String saveworkplace = "Student";
            String saveuserBossName = "Boss";
            saveworkplace = inuserName.getText().toString();
            saveuserBossName = inuserBossName.getText().toString();
            TextuserName.setText(getString(R.string.firm_name) + String.valueOf(saveworkplace));
            TextuserBossName.setText(getString(R.string.instructor_name) + String.valueOf(saveuserBossName));
            final SharedPreferences pref2 = getApplicationContext().getSharedPreferences("userData",
                    MODE_APPEND);
            SharedPreferences.Editor editor = pref2.edit();
            editor.putString("userName", saveworkplace);
            editor.putString("userBoss", saveuserBossName);
            editor.putBoolean("data_saved", true);
            editor.commit();
            Snackbar snackbar = Snackbar.make(findViewById(android.R.id.content),
                    "Data saved. Restart the app to see changes.", Snackbar.LENGTH_LONG);
            snackbar.show();
            // finish();
            startActivity(getIntent());
        }
    });
    final SharedPreferences pref2 = getApplicationContext().getSharedPreferences("userData", MODE_APPEND);
    if (pref2.getBoolean("data_saved", true)) {
        String TextuserNameString = pref2.getString("userName", "");
        String TextuserBossNameString = pref2.getString("userBoss", "");
        TextuserName.setText(getString(R.string.firm_name) + String.valueOf(TextuserNameString));
        TextuserBossName.setText(getString(R.string.instructor_name) + String.valueOf(TextuserBossNameString));
        inuserName.setVisibility(View.GONE);
        inuserBossName.setVisibility(View.GONE);
        bSave.setVisibility(View.GONE);

    } else {
        Toast toast = Toast.makeText(this, "No data saved", Toast.LENGTH_SHORT);
        toast.show();
    }
    /*
    END SAVE SETTINGS
     */

}

From source file:com.geoffreybuttercrumbs.arewethereyet.DrawerFragment.java

protected void ringtonepicker() {
    Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_ALARM);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select Tone");
    if (uri != null) {
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, uri);
    } else {/*w w w. j  av  a2s  . com*/
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) null);
    }
    startActivityForResult(intent, Set_Ringtone);
    SlidingFragmentActivity sfa = (SlidingFragmentActivity) getActivity();
    sfa.showContent();
}

From source file:org.telegram.ui.NotificationsSettingsActivity.java

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("NotificationsAndSounds", R.string.NotificationsAndSounds));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override// w w w . j a  v a2s  .c  o m
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });

    fragmentView = new FrameLayout(context);
    fragmentView.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background));
    FrameLayout frameLayout = (FrameLayout) fragmentView;

    listView = new ListView(context);
    listView.setDivider(null);
    listView.setDividerHeight(0);
    listView.setVerticalScrollBarEnabled(false);
    frameLayout.addView(listView);
    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    listView.setLayoutParams(layoutParams);
    listView.setAdapter(new ListAdapter(context));
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, final View view, final int i, long l) {
            boolean enabled = false;
            if (i == messageAlertRow || i == groupAlertRow) {
                SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = preferences.edit();
                if (i == messageAlertRow) {
                    enabled = preferences.getBoolean("EnableAll", true);
                    editor.putBoolean("EnableAll", !enabled);
                } else if (i == groupAlertRow) {
                    enabled = preferences.getBoolean("EnableGroup", true);
                    editor.putBoolean("EnableGroup", !enabled);
                }
                editor.commit();
                updateServerNotificationsSettings(i == groupAlertRow);
            } else if (i == messagePreviewRow || i == groupPreviewRow) {
                SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = preferences.edit();
                if (i == messagePreviewRow) {
                    enabled = preferences.getBoolean("EnablePreviewAll", true);
                    editor.putBoolean("EnablePreviewAll", !enabled);
                } else if (i == groupPreviewRow) {
                    enabled = preferences.getBoolean("EnablePreviewGroup", true);
                    editor.putBoolean("EnablePreviewGroup", !enabled);
                }
                editor.commit();
                updateServerNotificationsSettings(i == groupPreviewRow);
            } else if (i == messageSoundRow || i == groupSoundRow) {
                try {
                    SharedPreferences preferences = ApplicationLoader.applicationContext
                            .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                    Intent tmpIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
                    tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
                    tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
                    tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI,
                            RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
                    Uri currentSound = null;

                    String defaultPath = null;
                    Uri defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI;
                    if (defaultUri != null) {
                        defaultPath = defaultUri.getPath();
                    }

                    if (i == messageSoundRow) {
                        String path = preferences.getString("GlobalSoundPath", defaultPath);
                        if (path != null && !path.equals("NoSound")) {
                            if (path.equals(defaultPath)) {
                                currentSound = defaultUri;
                            } else {
                                currentSound = Uri.parse(path);
                            }
                        }
                    } else if (i == groupSoundRow) {
                        String path = preferences.getString("GroupSoundPath", defaultPath);
                        if (path != null && !path.equals("NoSound")) {
                            if (path.equals(defaultPath)) {
                                currentSound = defaultUri;
                            } else {
                                currentSound = Uri.parse(path);
                            }
                        }
                    }
                    tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currentSound);
                    startActivityForResult(tmpIntent, i);
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
            } else if (i == resetNotificationsRow) {
                if (reseting) {
                    return;
                }
                reseting = true;
                TLRPC.TL_account_resetNotifySettings req = new TLRPC.TL_account_resetNotifySettings();
                ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
                    @Override
                    public void run(TLObject response, TLRPC.TL_error error) {
                        AndroidUtilities.runOnUIThread(new Runnable() {
                            @Override
                            public void run() {
                                MessagesController.getInstance().enableJoined = true;
                                reseting = false;
                                SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                SharedPreferences.Editor editor = preferences.edit();
                                editor.clear();
                                editor.commit();
                                if (listView != null) {
                                    listView.invalidateViews();
                                }
                                if (getParentActivity() != null) {
                                    Toast toast = Toast
                                            .makeText(getParentActivity(),
                                                    LocaleController.getString("ResetNotificationsText",
                                                            R.string.ResetNotificationsText),
                                                    Toast.LENGTH_SHORT);
                                    toast.show();
                                }
                            }
                        });
                    }
                });
            } else if (i == inappSoundRow) {
                SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = preferences.edit();
                enabled = preferences.getBoolean("EnableInAppSounds", true);
                editor.putBoolean("EnableInAppSounds", !enabled);
                editor.commit();
            } else if (i == inappVibrateRow) {
                SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = preferences.edit();
                enabled = preferences.getBoolean("EnableInAppVibrate", true);
                editor.putBoolean("EnableInAppVibrate", !enabled);
                editor.commit();
            } else if (i == inappPreviewRow) {
                SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = preferences.edit();
                enabled = preferences.getBoolean("EnableInAppPreview", true);
                editor.putBoolean("EnableInAppPreview", !enabled);
                editor.commit();
            } else if (i == inchatSoundRow) {
                SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = preferences.edit();
                enabled = preferences.getBoolean("EnableInChatSound", true);
                editor.putBoolean("EnableInChatSound", !enabled);
                editor.commit();
                NotificationsController.getInstance().setInChatSoundEnabled(!enabled);
            } else if (i == inappPriorityRow) {
                SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = preferences.edit();
                enabled = preferences.getBoolean("EnableInAppPriority", false);
                editor.putBoolean("EnableInAppPriority", !enabled);
                editor.commit();
            } else if (i == contactJoinedRow) {
                SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = preferences.edit();
                enabled = preferences.getBoolean("EnableContactJoined", true);
                MessagesController.getInstance().enableJoined = !enabled;
                editor.putBoolean("EnableContactJoined", !enabled);
                editor.commit();
            } else if (i == pinnedMessageRow) {
                SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = preferences.edit();
                enabled = preferences.getBoolean("PinnedMessages", true);
                editor.putBoolean("PinnedMessages", !enabled);
                editor.commit();
            } else if (i == androidAutoAlertRow) {
                SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = preferences.edit();
                enabled = preferences.getBoolean("EnableAutoNotifications", false);
                editor.putBoolean("EnableAutoNotifications", !enabled);
                editor.commit();
            } else if (i == badgeNumberRow) {
                SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = preferences.edit();
                enabled = preferences.getBoolean("badgeNumber", true);
                editor.putBoolean("badgeNumber", !enabled);
                editor.commit();
                NotificationsController.getInstance().setBadgeEnabled(!enabled);
            } else if (i == notificationsServiceConnectionRow) {
                SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                enabled = preferences.getBoolean("pushConnection", true);
                SharedPreferences.Editor editor = preferences.edit();
                editor.putBoolean("pushConnection", !enabled);
                editor.commit();
                if (!enabled) {
                    ConnectionsManager.getInstance().setPushConnectionEnabled(true);
                } else {
                    ConnectionsManager.getInstance().setPushConnectionEnabled(false);
                }
            } else if (i == notificationsServiceRow) {
                final SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                enabled = preferences.getBoolean("pushService", true);
                SharedPreferences.Editor editor = preferences.edit();
                editor.putBoolean("pushService", !enabled);
                editor.commit();
                if (!enabled) {
                    ApplicationLoader.startPushService();
                } else {
                    ApplicationLoader.stopPushService();
                }
                /*if (!enabled) {
                        
                } else {
                if (getParentActivity() == null) {
                    return;
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setMessage(LocaleController.getString("NotificationsServiceDisableInfo", R.string.NotificationsServiceDisableInfo));
                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        
                        final SharedPreferences.Editor editor = preferences.edit();
                        editor.putBoolean("pushService", false);
                        editor.commit();
                        listView.invalidateViews();
                    }
                });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        ((TextCheckCell) view).setChecked(true);
                    }
                });
                showDialog(builder.create());
                }*/
            } else if (i == messageLedRow || i == groupLedRow) {
                if (getParentActivity() == null) {
                    return;
                }

                LinearLayout linearLayout = new LinearLayout(getParentActivity());
                linearLayout.setOrientation(LinearLayout.VERTICAL);
                final ColorPickerView colorPickerView = new ColorPickerView(getParentActivity());
                linearLayout.addView(colorPickerView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT,
                        LayoutHelper.WRAP_CONTENT, Gravity.CENTER));

                SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                if (i == messageLedRow) {
                    colorPickerView.setOldCenterColor(preferences.getInt("MessagesLed", 0xff00ff00));
                } else if (i == groupLedRow) {
                    colorPickerView.setOldCenterColor(preferences.getInt("GroupLed", 0xff00ff00));
                }

                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("LedColor", R.string.LedColor));
                builder.setView(linearLayout);
                builder.setPositiveButton(LocaleController.getString("Set", R.string.Set),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int which) {
                                final SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                SharedPreferences.Editor editor = preferences.edit();
                                TextColorCell textCell = (TextColorCell) view;
                                if (i == messageLedRow) {
                                    editor.putInt("MessagesLed", colorPickerView.getColor());
                                    textCell.setTextAndColor(
                                            LocaleController.getString("LedColor", R.string.LedColor),
                                            colorPickerView.getColor(), true);
                                } else if (i == groupLedRow) {
                                    editor.putInt("GroupLed", colorPickerView.getColor());
                                    textCell.setTextAndColor(
                                            LocaleController.getString("LedColor", R.string.LedColor),
                                            colorPickerView.getColor(), true);
                                }
                                editor.commit();
                            }
                        });
                builder.setNeutralButton(LocaleController.getString("LedDisabled", R.string.LedDisabled),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                final SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                SharedPreferences.Editor editor = preferences.edit();
                                TextColorCell textCell = (TextColorCell) view;
                                if (i == messageLedRow) {
                                    editor.putInt("MessagesLed", 0);
                                    textCell.setTextAndColor(
                                            LocaleController.getString("LedColor", R.string.LedColor), 0, true);
                                } else if (i == groupLedRow) {
                                    editor.putInt("GroupLed", 0);
                                    textCell.setTextAndColor(
                                            LocaleController.getString("LedColor", R.string.LedColor), 0, true);
                                }
                                editor.commit();
                                listView.invalidateViews();
                            }
                        });
                showDialog(builder.create());
            } else if (i == messagePopupNotificationRow || i == groupPopupNotificationRow) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("PopupNotification", R.string.PopupNotification));
                builder.setItems(
                        new CharSequence[] { LocaleController.getString("NoPopup", R.string.NoPopup),
                                LocaleController.getString("OnlyWhenScreenOn", R.string.OnlyWhenScreenOn),
                                LocaleController.getString("OnlyWhenScreenOff", R.string.OnlyWhenScreenOff),
                                LocaleController.getString("AlwaysShowPopup", R.string.AlwaysShowPopup) },
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                SharedPreferences.Editor editor = preferences.edit();
                                if (i == messagePopupNotificationRow) {
                                    editor.putInt("popupAll", which);
                                } else if (i == groupPopupNotificationRow) {
                                    editor.putInt("popupGroup", which);
                                }
                                editor.commit();
                                if (listView != null) {
                                    listView.invalidateViews();
                                }
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
            } else if (i == messageVibrateRow || i == groupVibrateRow) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("Vibrate", R.string.Vibrate));
                builder.setItems(
                        new CharSequence[] {
                                LocaleController.getString("VibrationDisabled", R.string.VibrationDisabled),
                                LocaleController.getString("VibrationDefault", R.string.VibrationDefault),
                                LocaleController.getString("Short", R.string.Short),
                                LocaleController.getString("Long", R.string.Long),
                                LocaleController.getString("OnlyIfSilent", R.string.OnlyIfSilent) },
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                SharedPreferences.Editor editor = preferences.edit();
                                String param = "vibrate_messages";
                                if (i == groupVibrateRow) {
                                    param = "vibrate_group";
                                }
                                if (which == 0) {
                                    editor.putInt(param, 2);
                                } else if (which == 1) {
                                    editor.putInt(param, 0);
                                } else if (which == 2) {
                                    editor.putInt(param, 1);
                                } else if (which == 3) {
                                    editor.putInt(param, 3);
                                } else if (which == 4) {
                                    editor.putInt(param, 4);
                                }
                                editor.commit();
                                if (listView != null) {
                                    listView.invalidateViews();
                                }
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
            } else if (i == messagePriorityRow || i == groupPriorityRow) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(
                        LocaleController.getString("NotificationsPriority", R.string.NotificationsPriority));
                builder.setItems(new CharSequence[] {
                        LocaleController.getString("NotificationsPriorityDefault",
                                R.string.NotificationsPriorityDefault),
                        LocaleController.getString("NotificationsPriorityHigh",
                                R.string.NotificationsPriorityHigh),
                        LocaleController.getString("NotificationsPriorityMax",
                                R.string.NotificationsPriorityMax) },
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                if (i == messagePriorityRow) {
                                    preferences.edit().putInt("priority_messages", which).commit();
                                } else if (i == groupPriorityRow) {
                                    preferences.edit().putInt("priority_group", which).commit();
                                }
                                if (listView != null) {
                                    listView.invalidateViews();
                                }
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
            } else if (i == repeatRow) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(
                        LocaleController.getString("RepeatNotifications", R.string.RepeatNotifications));
                builder.setItems(
                        new CharSequence[] {
                                LocaleController.getString("RepeatDisabled", R.string.RepeatDisabled),
                                LocaleController.formatPluralString("Minutes", 5),
                                LocaleController.formatPluralString("Minutes", 10),
                                LocaleController.formatPluralString("Minutes", 30),
                                LocaleController.formatPluralString("Hours", 1),
                                LocaleController.formatPluralString("Hours", 2),
                                LocaleController.formatPluralString("Hours", 4) },
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                int minutes = 0;
                                if (which == 1) {
                                    minutes = 5;
                                } else if (which == 2) {
                                    minutes = 10;
                                } else if (which == 3) {
                                    minutes = 30;
                                } else if (which == 4) {
                                    minutes = 60;
                                } else if (which == 5) {
                                    minutes = 60 * 2;
                                } else if (which == 6) {
                                    minutes = 60 * 4;
                                }
                                SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                preferences.edit().putInt("repeat_messages", minutes).commit();
                                if (listView != null) {
                                    listView.invalidateViews();
                                }
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
            }
            if (view instanceof TextCheckCell) {
                ((TextCheckCell) view).setChecked(!enabled);
            }
        }
    });

    return fragmentView;
}

From source file:org.telegram.ui.ProfileNotificationsActivity.java

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("NotificationsAndSounds", R.string.NotificationsAndSounds));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override//from  w  ww  . j  a  va2s. c o  m
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });

    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));

    listView = new ListView(context);
    listView.setDivider(null);
    listView.setDividerHeight(0);
    listView.setVerticalScrollBarEnabled(false);
    AndroidUtilities.setListViewEdgeEffectColor(listView, AvatarDrawable.getProfileBackColorForId(5));
    frameLayout.addView(listView);
    final FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    listView.setLayoutParams(layoutParams);
    listView.setAdapter(new ListAdapter(context));
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
            if (i == settingsVibrateRow) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("Vibrate", R.string.Vibrate));
                builder.setItems(
                        new CharSequence[] {
                                LocaleController.getString("VibrationDisabled", R.string.VibrationDisabled),
                                LocaleController.getString("SettingsDefault", R.string.SettingsDefault),
                                LocaleController.getString("SystemDefault", R.string.SystemDefault),
                                LocaleController.getString("Short", R.string.Short),
                                LocaleController.getString("Long", R.string.Long) },
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                SharedPreferences.Editor editor = preferences.edit();
                                if (which == 0) {
                                    editor.putInt("vibrate_" + dialog_id, 2);
                                } else if (which == 1) {
                                    editor.putInt("vibrate_" + dialog_id, 0);
                                } else if (which == 2) {
                                    editor.putInt("vibrate_" + dialog_id, 4);
                                } else if (which == 3) {
                                    editor.putInt("vibrate_" + dialog_id, 1);
                                } else if (which == 4) {
                                    editor.putInt("vibrate_" + dialog_id, 3);
                                }
                                editor.commit();
                                if (listView != null) {
                                    listView.invalidateViews();
                                }
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
            } else if (i == settingsNotificationsRow) {
                if (getParentActivity() == null) {
                    return;
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                builder.setItems(
                        new CharSequence[] { LocaleController.getString("Default", R.string.Default),
                                LocaleController.getString("Enabled", R.string.Enabled),
                                LocaleController.getString("NotificationsDisabled",
                                        R.string.NotificationsDisabled) },
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface d, int which) {
                                SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                SharedPreferences.Editor editor = preferences.edit();
                                editor.putInt("notify2_" + dialog_id, which);
                                if (which == 2) {
                                    NotificationsController.getInstance()
                                            .removeNotificationsForDialog(dialog_id);
                                }
                                MessagesStorage.getInstance().setDialogFlags(dialog_id, which == 2 ? 1 : 0);
                                editor.commit();
                                TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs_dict
                                        .get(dialog_id);
                                if (dialog != null) {
                                    dialog.notify_settings = new TLRPC.TL_peerNotifySettings();
                                    if (which == 2) {
                                        dialog.notify_settings.mute_until = Integer.MAX_VALUE;
                                    }
                                }
                                if (listView != null) {
                                    listView.invalidateViews();
                                }
                                NotificationsController.updateServerNotificationsSettings(dialog_id);
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
            } else if (i == settingsSoundRow) {
                try {
                    Intent tmpIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
                    tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
                    tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
                    tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI,
                            RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
                    SharedPreferences preferences = ApplicationLoader.applicationContext
                            .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                    Uri currentSound = null;

                    String defaultPath = null;
                    Uri defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI;
                    if (defaultUri != null) {
                        defaultPath = defaultUri.getPath();
                    }

                    String path = preferences.getString("sound_path_" + dialog_id, defaultPath);
                    if (path != null && !path.equals("NoSound")) {
                        if (path.equals(defaultPath)) {
                            currentSound = defaultUri;
                        } else {
                            currentSound = Uri.parse(path);
                        }
                    }

                    tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currentSound);
                    startActivityForResult(tmpIntent, 12);
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
            } else if (i == settingsLedRow) {
                if (getParentActivity() == null) {
                    return;
                }

                LinearLayout linearLayout = new LinearLayout(getParentActivity());
                linearLayout.setOrientation(LinearLayout.VERTICAL);
                final ColorPickerView colorPickerView = new ColorPickerView(getParentActivity());
                linearLayout.addView(colorPickerView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT,
                        LayoutHelper.WRAP_CONTENT, Gravity.CENTER));

                SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                if (preferences.contains("color_" + dialog_id)) {
                    colorPickerView.setOldCenterColor(preferences.getInt("color_" + dialog_id, 0xff00ff00));
                } else {
                    if ((int) dialog_id < 0) {
                        colorPickerView.setOldCenterColor(preferences.getInt("GroupLed", 0xff00ff00));
                    } else {
                        colorPickerView.setOldCenterColor(preferences.getInt("MessagesLed", 0xff00ff00));
                    }
                }

                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("LedColor", R.string.LedColor));
                builder.setView(linearLayout);
                builder.setPositiveButton(LocaleController.getString("Set", R.string.Set),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int which) {
                                final SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                SharedPreferences.Editor editor = preferences.edit();
                                editor.putInt("color_" + dialog_id, colorPickerView.getColor());
                                editor.commit();
                                listView.invalidateViews();
                            }
                        });
                builder.setNeutralButton(LocaleController.getString("LedDisabled", R.string.LedDisabled),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                final SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                SharedPreferences.Editor editor = preferences.edit();
                                editor.putInt("color_" + dialog_id, 0);
                                editor.commit();
                                listView.invalidateViews();
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("Default", R.string.Default),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                final SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                SharedPreferences.Editor editor = preferences.edit();
                                editor.remove("color_" + dialog_id);
                                editor.commit();
                                listView.invalidateViews();
                            }
                        });
                showDialog(builder.create());
            } else if (i == settingsPriorityRow) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(
                        LocaleController.getString("NotificationsPriority", R.string.NotificationsPriority));
                builder.setItems(
                        new CharSequence[] {
                                LocaleController.getString("SettingsDefault", R.string.SettingsDefault),
                                LocaleController.getString("NotificationsPriorityDefault",
                                        R.string.NotificationsPriorityDefault),
                                LocaleController.getString("NotificationsPriorityHigh",
                                        R.string.NotificationsPriorityHigh),
                                LocaleController.getString("NotificationsPriorityMax",
                                        R.string.NotificationsPriorityMax) },
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                if (which == 0) {
                                    which = 3;
                                } else {
                                    which--;
                                }
                                SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                preferences.edit().putInt("priority_" + dialog_id, which).commit();
                                if (listView != null) {
                                    listView.invalidateViews();
                                }
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
            } else if (i == smartRow) {
                if (getParentActivity() == null) {
                    return;
                }
                SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                int notifyMaxCount = preferences.getInt("smart_max_count_" + dialog_id, 2);
                int notifyDelay = preferences.getInt("smart_delay_" + dialog_id, 3 * 60);
                if (notifyMaxCount == 0) {
                    notifyMaxCount = 2;
                }

                LinearLayout linearLayout = new LinearLayout(getParentActivity());
                linearLayout.setOrientation(LinearLayout.VERTICAL);

                LinearLayout linearLayout2 = new LinearLayout(getParentActivity());
                linearLayout2.setOrientation(LinearLayout.HORIZONTAL);
                linearLayout.addView(linearLayout2);
                LinearLayout.LayoutParams layoutParams1 = (LinearLayout.LayoutParams) linearLayout2
                        .getLayoutParams();
                layoutParams1.width = LayoutHelper.WRAP_CONTENT;
                layoutParams1.height = LayoutHelper.WRAP_CONTENT;
                layoutParams1.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
                linearLayout2.setLayoutParams(layoutParams1);

                TextView textView = new TextView(getParentActivity());
                textView.setText(LocaleController.getString("SmartNotificationsSoundAtMost",
                        R.string.SmartNotificationsSoundAtMost));
                textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
                linearLayout2.addView(textView);
                layoutParams1 = (LinearLayout.LayoutParams) textView.getLayoutParams();
                layoutParams1.width = LayoutHelper.WRAP_CONTENT;
                layoutParams1.height = LayoutHelper.WRAP_CONTENT;
                layoutParams1.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT;
                textView.setLayoutParams(layoutParams1);

                final NumberPicker numberPickerTimes = new NumberPicker(getParentActivity());
                numberPickerTimes.setMinValue(1);
                numberPickerTimes.setMaxValue(10);
                numberPickerTimes.setValue(notifyMaxCount);
                linearLayout2.addView(numberPickerTimes);
                layoutParams1 = (LinearLayout.LayoutParams) numberPickerTimes.getLayoutParams();
                layoutParams1.width = AndroidUtilities.dp(50);
                numberPickerTimes.setLayoutParams(layoutParams1);

                textView = new TextView(getParentActivity());
                textView.setText(LocaleController.getString("SmartNotificationsTimes",
                        R.string.SmartNotificationsTimes));
                textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
                linearLayout2.addView(textView);
                layoutParams1 = (LinearLayout.LayoutParams) textView.getLayoutParams();
                layoutParams1.width = LayoutHelper.WRAP_CONTENT;
                layoutParams1.height = LayoutHelper.WRAP_CONTENT;
                layoutParams1.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT;
                textView.setLayoutParams(layoutParams1);

                linearLayout2 = new LinearLayout(getParentActivity());
                linearLayout2.setOrientation(LinearLayout.HORIZONTAL);
                linearLayout.addView(linearLayout2);
                layoutParams1 = (LinearLayout.LayoutParams) linearLayout2.getLayoutParams();
                layoutParams1.width = LayoutHelper.WRAP_CONTENT;
                layoutParams1.height = LayoutHelper.WRAP_CONTENT;
                layoutParams1.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
                linearLayout2.setLayoutParams(layoutParams1);

                textView = new TextView(getParentActivity());
                textView.setText(LocaleController.getString("SmartNotificationsWithin",
                        R.string.SmartNotificationsWithin));
                textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
                linearLayout2.addView(textView);
                layoutParams1 = (LinearLayout.LayoutParams) textView.getLayoutParams();
                layoutParams1.width = LayoutHelper.WRAP_CONTENT;
                layoutParams1.height = LayoutHelper.WRAP_CONTENT;
                layoutParams1.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT;
                textView.setLayoutParams(layoutParams1);

                final NumberPicker numberPickerMinutes = new NumberPicker(getParentActivity());
                numberPickerMinutes.setMinValue(1);
                numberPickerMinutes.setMaxValue(10);
                numberPickerMinutes.setValue(notifyDelay / 60);
                linearLayout2.addView(numberPickerMinutes);
                layoutParams1 = (LinearLayout.LayoutParams) numberPickerMinutes.getLayoutParams();
                layoutParams1.width = AndroidUtilities.dp(50);
                numberPickerMinutes.setLayoutParams(layoutParams1);

                textView = new TextView(getParentActivity());
                textView.setText(LocaleController.getString("SmartNotificationsMinutes",
                        R.string.SmartNotificationsMinutes));
                textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
                linearLayout2.addView(textView);
                layoutParams1 = (LinearLayout.LayoutParams) textView.getLayoutParams();
                layoutParams1.width = LayoutHelper.WRAP_CONTENT;
                layoutParams1.height = LayoutHelper.WRAP_CONTENT;
                layoutParams1.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT;
                textView.setLayoutParams(layoutParams1);

                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("SmartNotifications", R.string.SmartNotifications));
                builder.setView(linearLayout);
                builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                preferences.edit()
                                        .putInt("smart_max_count_" + dialog_id, numberPickerTimes.getValue())
                                        .commit();
                                preferences.edit()
                                        .putInt("smart_delay_" + dialog_id, numberPickerMinutes.getValue() * 60)
                                        .commit();
                                if (listView != null) {
                                    listView.invalidateViews();
                                }
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("SmartNotificationsDisabled",
                        R.string.SmartNotificationsDisabled), new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                preferences.edit().putInt("smart_max_count_" + dialog_id, 0).commit();
                                if (listView != null) {
                                    listView.invalidateViews();
                                }
                            }
                        });
                showDialog(builder.create());
            }
        }
    });

    return fragmentView;
}

From source file:nkarasch.repeatingreminder.gui.AlertView.java

@OnClick(R.id.text_tone)
public void toneOnClick() {
    Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select Tone");
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) null);
    mContext.getIntent().putExtra("array_index", mPosition);
    mContext.startActivityForResult(intent, 5);
    stopAlert();//from   www.  j  a  va2  s.  co  m
}

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

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final Context appContext = getActivity().getApplicationContext();

    // retrieve the arguments
    Bundle args = getArguments();/* w w w.j a  v  a2 s  .  c  om*/
    String matrixId = args.getString(ARG_MATRIX_ID);
    mSession = Matrix.getInstance(appContext).getSession(matrixId);

    // sanity checks
    if ((null == mSession) || !mSession.isAlive()) {
        getActivity().finish();
        return;
    }

    // define the layout
    addPreferencesFromResource(R.xml.vector_settings_preferences);

    if (null == mPushesRuleByResourceId) {
        mPushesRuleByResourceId = new HashMap<>();

        mPushesRuleByResourceId.put(PreferencesManager.SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY,
                BingRule.RULE_ID_DISABLE_ALL);
        mPushesRuleByResourceId.put(PreferencesManager.SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY, DUMMY_RULE);
        mPushesRuleByResourceId.put(PreferencesManager.SETTINGS_TURN_SCREEN_ON_PREFERENCE_KEY, DUMMY_RULE);
        mPushesRuleByResourceId.put(PreferencesManager.SETTINGS_CONTAINING_MY_DISPLAY_NAME_PREFERENCE_KEY,
                BingRule.RULE_ID_CONTAIN_DISPLAY_NAME);
        mPushesRuleByResourceId.put(PreferencesManager.SETTINGS_CONTAINING_MY_USER_NAME_PREFERENCE_KEY,
                BingRule.RULE_ID_CONTAIN_USER_NAME);
        mPushesRuleByResourceId.put(PreferencesManager.SETTINGS_MESSAGES_IN_ONE_TO_ONE_PREFERENCE_KEY,
                BingRule.RULE_ID_ONE_TO_ONE_ROOM);
        mPushesRuleByResourceId.put(PreferencesManager.SETTINGS_MESSAGES_IN_GROUP_CHAT_PREFERENCE_KEY,
                BingRule.RULE_ID_ALL_OTHER_MESSAGES_ROOMS);
        mPushesRuleByResourceId.put(PreferencesManager.SETTINGS_INVITED_TO_ROOM_PREFERENCE_KEY,
                BingRule.RULE_ID_INVITE_ME);
        mPushesRuleByResourceId.put(PreferencesManager.SETTINGS_CALL_INVITATIONS_PREFERENCE_KEY,
                BingRule.RULE_ID_CALL);
        mPushesRuleByResourceId.put(PreferencesManager.SETTINGS_MESSAGES_SENT_BY_BOT_PREFERENCE_KEY,
                BingRule.RULE_ID_SUPPRESS_BOTS_NOTIFICATIONS);
    }

    UserAvatarPreference avatarPreference = (UserAvatarPreference) findPreference(
            PreferencesManager.SETTINGS_PROFILE_PICTURE_PREFERENCE_KEY);
    avatarPreference.setSession(mSession);
    avatarPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            onUpdateAvatarClick();
            return false;
        }
    });

    EditTextPreference passwordPreference = (EditTextPreference) findPreference(
            PreferencesManager.SETTINGS_CHANGE_PASSWORD_PREFERENCE_KEY);
    passwordPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            onPasswordUpdateClick();
            return false;
        }
    });

    EditTextPreference notificationRingTonePreference = (EditTextPreference) findPreference(
            PreferencesManager.SETTINGS_NOTIFICATION_RINGTONE_SELECTION_PREFERENCE_KEY);
    notificationRingTonePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);

            if (null != PreferencesManager.getNotificationRingTone(getActivity())) {
                intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI,
                        PreferencesManager.getNotificationRingTone(getActivity()));
            }
            getActivity().startActivityForResult(intent, REQUEST_NOTIFICATION_RINGTONE);
            return false;
        }
    });
    refreshNotificationRingTone();

    EditTextPreference notificationPrivacyPreference = (EditTextPreference) findPreference(
            PreferencesManager.SETTINGS_NOTIFICATION_PRIVACY_PREFERENCE_KEY);
    if (notificationPrivacyPreference != null) {
        notificationPrivacyPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                startActivity(NotificationPrivacyActivity.getIntent(getActivity()));
                return true;
            }
        });
        refreshNotificationPrivacy();
    }

    // application version
    VectorCustomActionEditTextPreference versionTextPreference = (VectorCustomActionEditTextPreference) findPreference(
            PreferencesManager.SETTINGS_VERSION_PREFERENCE_KEY);
    if (null != versionTextPreference) {
        versionTextPreference.setSummary(VectorUtils.getApplicationVersion(appContext));

        versionTextPreference.setOnPreferenceLongClickListener(
                new VectorCustomActionEditTextPreference.OnPreferenceLongClickListener() {
                    @Override
                    public boolean onPreferenceLongClick(Preference preference) {
                        VectorUtils.copyToClipboard(appContext, VectorUtils.getApplicationVersion(appContext));
                        return true;
                    }
                });
    }

    // olm version
    EditTextPreference olmTextPreference = (EditTextPreference) findPreference(
            PreferencesManager.SETTINGS_OLM_VERSION_PREFERENCE_KEY);
    if (null != olmTextPreference) {
        olmTextPreference.setSummary(
                Matrix.getInstance(appContext).getDefaultSession().getCryptoVersion(appContext, false));
    }

    // user account
    EditTextPreference accountIdTextPreference = (EditTextPreference) findPreference(
            PreferencesManager.SETTINGS_LOGGED_IN_PREFERENCE_KEY);
    if (null != accountIdTextPreference) {
        accountIdTextPreference.setSummary(mSession.getMyUserId());
    }

    // home server
    EditTextPreference homeServerTextPreference = (EditTextPreference) findPreference(
            PreferencesManager.SETTINGS_HOME_SERVER_PREFERENCE_KEY);
    if (null != homeServerTextPreference) {
        homeServerTextPreference.setSummary(mSession.getHomeServerConfig().getHomeserverUri().toString());
    }

    // identity server
    EditTextPreference identityServerTextPreference = (EditTextPreference) findPreference(
            PreferencesManager.SETTINGS_IDENTITY_SERVER_PREFERENCE_KEY);
    if (null != identityServerTextPreference) {
        identityServerTextPreference
                .setSummary(mSession.getHomeServerConfig().getIdentityServerUri().toString());
    }

    // terms & conditions
    EditTextPreference termConditionsPreference = (EditTextPreference) findPreference(
            PreferencesManager.SETTINGS_APP_TERM_CONDITIONS_PREFERENCE_KEY);

    if (null != termConditionsPreference) {
        termConditionsPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                VectorUtils.displayAppTac();
                return false;
            }
        });
    }

    // Themes
    ListPreference themePreference = (ListPreference) findPreference(ThemeUtils.APPLICATION_THEME_KEY);

    if (null != themePreference) {
        themePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                if (newValue instanceof String) {
                    VectorApp.updateApplicationTheme((String) newValue);
                    getActivity().startActivity(getActivity().getIntent());
                    getActivity().finish();
                    return true;
                } else {
                    return false;
                }
            }
        });
    }

    // privacy policy
    EditTextPreference privacyPreference = (EditTextPreference) findPreference(
            PreferencesManager.SETTINGS_PRIVACY_POLICY_PREFERENCE_KEY);

    if (null != privacyPreference) {
        privacyPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                VectorUtils.displayAppPrivacyPolicy();
                return false;
            }
        });
    }

    // third party notice
    EditTextPreference thirdPartyNotices = (EditTextPreference) findPreference(
            PreferencesManager.SETTINGS_THIRD_PARTY_NOTICES_PREFERENCE_KEY);

    if (null != thirdPartyNotices) {
        thirdPartyNotices.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                VectorUtils.displayThirdPartyLicenses();
                return false;
            }
        });
    }

    // copyright
    EditTextPreference copyrightNotices = (EditTextPreference) findPreference(
            PreferencesManager.SETTINGS_COPYRIGHT_PREFERENCE_KEY);

    if (null != copyrightNotices) {
        copyrightNotices.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                VectorUtils.displayAppCopyright();
                return false;
            }
        });
    }

    // update keep medias period
    final EditTextPreference keepMediaPeriodPreference = (EditTextPreference) findPreference(
            PreferencesManager.SETTINGS_MEDIA_SAVING_PERIOD_KEY);

    if (null != keepMediaPeriodPreference) {
        keepMediaPeriodPreference
                .setSummary(PreferencesManager.getSelectedMediasSavingPeriodString(getActivity()));

        keepMediaPeriodPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                new AlertDialog.Builder(getActivity())
                        .setSingleChoiceItems(PreferencesManager.getMediasSavingItemsChoicesList(getActivity()),
                                PreferencesManager.getSelectedMediasSavingPeriod(getActivity()),
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface d, int n) {
                                        PreferencesManager.setSelectedMediasSavingPeriod(getActivity(), n);
                                        d.cancel();

                                        keepMediaPeriodPreference.setSummary(PreferencesManager
                                                .getSelectedMediasSavingPeriodString(getActivity()));
                                    }
                                })
                        .show();
                return false;
            }
        });
    }

    // clear medias cache
    final EditTextPreference clearMediaCachePreference = (EditTextPreference) findPreference(
            PreferencesManager.SETTINGS_CLEAR_MEDIA_CACHE_PREFERENCE_KEY);

    if (null != clearMediaCachePreference) {
        MXMediasCache.getCachesSize(getActivity(), new SimpleApiCallback<Long>() {
            @Override
            public void onSuccess(Long size) {
                if (null != getActivity()) {
                    clearMediaCachePreference
                            .setSummary(android.text.format.Formatter.formatFileSize(getActivity(), size));
                }
            }
        });

        clearMediaCachePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                displayLoadingView();

                AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
                    @Override
                    protected Void doInBackground(Void... params) {
                        mSession.getMediasCache().clear();
                        Glide.get(getActivity()).clearDiskCache();
                        return null;
                    }

                    @Override
                    protected void onPostExecute(Void result) {
                        hideLoadingView();

                        MXMediasCache.getCachesSize(getActivity(), new SimpleApiCallback<Long>() {
                            @Override
                            public void onSuccess(Long size) {
                                clearMediaCachePreference.setSummary(
                                        android.text.format.Formatter.formatFileSize(getActivity(), size));
                            }
                        });
                    }
                };

                try {
                    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                } catch (Exception e) {
                    Log.e(LOG_TAG, "## mSession.getMediasCache().clear() failed " + e.getMessage());
                    task.cancel(true);
                    hideLoadingView();
                }
                return false;
            }
        });
    }

    // clear cache
    final EditTextPreference clearCachePreference = (EditTextPreference) findPreference(
            PreferencesManager.SETTINGS_CLEAR_CACHE_PREFERENCE_KEY);

    if (null != clearCachePreference) {
        MXSession.getApplicationSizeCaches(getActivity(), new SimpleApiCallback<Long>() {
            @Override
            public void onSuccess(Long size) {
                if (null != getActivity()) {
                    clearCachePreference
                            .setSummary(android.text.format.Formatter.formatFileSize(getActivity(), size));
                }
            }
        });

        clearCachePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                displayLoadingView();
                Matrix.getInstance(appContext).reloadSessions(appContext);
                return false;
            }
        });
    }

    final EditTextPreference displaynamePref = (EditTextPreference) findPreference(
            PreferencesManager.SETTINGS_DISPLAY_NAME_PREFERENCE_KEY);
    displaynamePref.setSummary(mSession.getMyUser().displayname);
    displaynamePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            onDisplayNameClick((null == newValue) ? null : ((String) newValue).trim());
            return false;
        }
    });

    final VectorSwitchPreference urlPreviewPreference = (VectorSwitchPreference) findPreference(
            PreferencesManager.SETTINGS_SHOW_URL_PREVIEW_KEY);
    urlPreviewPreference.setChecked(mSession.isURLPreviewEnabled());

    urlPreviewPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {

            if ((null != newValue) && ((boolean) newValue != mSession.isURLPreviewEnabled())) {
                displayLoadingView();
                mSession.setURLPreviewStatus((boolean) newValue, new ApiCallback<Void>() {
                    @Override
                    public void onSuccess(Void info) {
                        urlPreviewPreference.setChecked(mSession.isURLPreviewEnabled());
                        hideLoadingView();
                    }

                    private void onError(String errorMessage) {
                        if (null != getActivity()) {
                            Toast.makeText(getActivity(), errorMessage, Toast.LENGTH_SHORT).show();
                        }
                        onSuccess(null);
                    }

                    @Override
                    public void onNetworkError(Exception e) {
                        onError(e.getLocalizedMessage());
                    }

                    @Override
                    public void onMatrixError(MatrixError e) {
                        onError(e.getLocalizedMessage());
                    }

                    @Override
                    public void onUnexpectedError(Exception e) {
                        onError(e.getLocalizedMessage());
                    }
                });
            }

            return false;
        }
    });

    // push rules
    for (String resourceText : mPushesRuleByResourceId.keySet()) {
        final Preference preference = findPreference(resourceText);

        if (null != preference) {
            if (preference instanceof CheckBoxPreference) {
                preference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
                    @Override
                    public boolean onPreferenceChange(Preference preference, Object newValueAsVoid) {
                        // on some old android APIs,
                        // the callback is called even if there is no user interaction
                        // so the value will be checked to ensure there is really no update.
                        onPushRuleClick(preference.getKey(), (boolean) newValueAsVoid);
                        return true;
                    }
                });
            } else if (preference instanceof BingRulePreference) {
                final BingRulePreference bingRulePreference = (BingRulePreference) preference;
                bingRulePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
                    @Override
                    public boolean onPreferenceClick(Preference preference) {
                        new AlertDialog.Builder(getActivity()).setSingleChoiceItems(
                                bingRulePreference.getBingRuleStatuses(),
                                bingRulePreference.getRuleStatusIndex(), new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface d, int index) {
                                        BingRule rule = bingRulePreference.createRule(index);
                                        d.cancel();

                                        if (null != rule) {
                                            displayLoadingView();
                                            mSession.getDataHandler().getBingRulesManager().updateRule(
                                                    bingRulePreference.getRule(), rule,
                                                    new BingRulesManager.onBingRuleUpdateListener() {
                                                        private void onDone() {
                                                            refreshDisplay();
                                                            hideLoadingView();
                                                        }

                                                        @Override
                                                        public void onBingRuleUpdateSuccess() {
                                                            onDone();
                                                        }

                                                        @Override
                                                        public void onBingRuleUpdateFailure(
                                                                String errorMessage) {
                                                            if (null != getActivity()) {
                                                                Toast.makeText(getActivity(), errorMessage,
                                                                        Toast.LENGTH_SHORT).show();
                                                            }
                                                            onDone();
                                                        }
                                                    });
                                        }
                                    }
                                }).show();
                        return true;
                    }
                });
            }
        }
    }

    // background sync tuning settings
    // these settings are useless and hidden if the app is registered to the GCM push service
    final GcmRegistrationManager gcmMgr = Matrix.getInstance(appContext).getSharedGCMRegistrationManager();
    if (gcmMgr.useGCM() && gcmMgr.hasRegistrationToken()) {
        // Hide the section
        PreferenceScreen preferenceScreen = getPreferenceScreen();
        PreferenceCategory backgroundSyncCategory = (PreferenceCategory) findPreference(
                PreferencesManager.SETTINGS_BACKGROUND_SYNC_PREFERENCE_KEY);
        PreferenceCategory backgroundSyncDivider = (PreferenceCategory) findPreference(
                PreferencesManager.SETTINGS_BACKGROUND_SYNC_DIVIDER_PREFERENCE_KEY);

        preferenceScreen.removePreference(backgroundSyncDivider);
        preferenceScreen.removePreference(backgroundSyncCategory);
    } else {
        mSyncRequestTimeoutPreference = (EditTextPreference) findPreference(
                PreferencesManager.SETTINGS_SET_SYNC_TIMEOUT_PREFERENCE_KEY);
        mSyncRequestDelayPreference = (EditTextPreference) findPreference(
                PreferencesManager.SETTINGS_SET_SYNC_DELAY_PREFERENCE_KEY);
        final CheckBoxPreference useBackgroundSyncPref = (CheckBoxPreference) findPreference(
                PreferencesManager.SETTINGS_ENABLE_BACKGROUND_SYNC_PREFERENCE_KEY);

        if (null != useBackgroundSyncPref) {

            final GcmRegistrationManager.ThirdPartyRegistrationListener listener = new GcmRegistrationManager.ThirdPartyRegistrationListener() {

                @Override
                public void onThirdPartyRegistered() {
                    hideLoadingView();
                }

                @Override
                public void onThirdPartyRegistrationFailed() {
                    hideLoadingView();
                }

                @Override
                public void onThirdPartyUnregistered() {
                    hideLoadingView();
                }

                @Override
                public void onThirdPartyUnregistrationFailed() {
                    hideLoadingView();
                }
            };

            if (null != useBackgroundSyncPref) {
                useBackgroundSyncPref.setChecked(gcmMgr.isBackgroundSyncAllowed());

                useBackgroundSyncPref
                        .setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
                            @Override
                            public boolean onPreferenceChange(Preference preference, Object aNewValue) {
                                final boolean newValue = (boolean) aNewValue;

                                if (newValue != gcmMgr.isBackgroundSyncAllowed()) {
                                    gcmMgr.setBackgroundSyncAllowed(newValue);
                                }

                                displayLoadingView();

                                Matrix.getInstance(VectorSettingsPreferencesFragment.this.getActivity())
                                        .getSharedGCMRegistrationManager().forceSessionsRegistration(listener);

                                return true;
                            }
                        });
            }
        }
    }

    mUserSettingsCategory = (PreferenceCategory) findPreference(
            PreferencesManager.SETTINGS_USER_SETTINGS_PREFERENCE_KEY);
    mContactSettingsCategory = (PreferenceCategory) findPreference(
            PreferencesManager.SETTINGS_CONTACT_PREFERENCE_KEYS);
    mPushersSettingsCategory = (PreferenceCategory) findPreference(
            PreferencesManager.SETTINGS_NOTIFICATIONS_TARGETS_PREFERENCE_KEY);
    mPushersSettingsDivider = (PreferenceCategory) findPreference(
            PreferencesManager.SETTINGS_NOTIFICATIONS_TARGET_DIVIDER_PREFERENCE_KEY);
    mIgnoredUserSettingsCategory = (PreferenceCategory) findPreference(
            PreferencesManager.SETTINGS_IGNORED_USERS_PREFERENCE_KEY);
    mIgnoredUserSettingsCategoryDivider = (PreferenceCategory) findPreference(
            PreferencesManager.SETTINGS_IGNORE_USERS_DIVIDER_PREFERENCE_KEY);
    mDevicesListSettingsCategory = (PreferenceCategory) findPreference(
            PreferencesManager.SETTINGS_DEVICES_LIST_PREFERENCE_KEY);
    mDevicesListSettingsCategoryDivider = (PreferenceCategory) findPreference(
            PreferencesManager.SETTINGS_DEVICES_DIVIDER_PREFERENCE_KEY);
    mCryptographyCategory = (PreferenceCategory) findPreference(
            PreferencesManager.SETTINGS_CRYPTOGRAPHY_PREFERENCE_KEY);
    mCryptographyCategoryDivider = (PreferenceCategory) findPreference(
            PreferencesManager.SETTINGS_CRYPTOGRAPHY_DIVIDER_PREFERENCE_KEY);
    mLabsCategory = (PreferenceCategory) findPreference(PreferencesManager.SETTINGS_LABS_PREFERENCE_KEY);
    mGroupsFlairCategory = (PreferenceCategory) findPreference(PreferencesManager.SETTINGS_GROUPS_FLAIR_KEY);

    // preference to start the App info screen, to facilitate App permissions access
    Preference applicationInfoLInkPref = findPreference(APP_INFO_LINK_PREFERENCE_KEY);
    applicationInfoLInkPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            if (null != getActivity()) {
                Intent intent = new Intent();
                intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                Uri uri = Uri.fromParts("package", appContext.getPackageName(), null);
                intent.setData(uri);
                getActivity().getApplicationContext().startActivity(intent);
            }

            return true;
        }
    });

    // Contacts
    setContactsPreferences();

    // user interface preferences
    setUserInterfacePreferences();

    final CheckBoxPreference useCryptoPref = (CheckBoxPreference) findPreference(
            PreferencesManager.SETTINGS_ROOM_SETTINGS_LABS_END_TO_END_PREFERENCE_KEY);
    final Preference cryptoIsEnabledPref = findPreference(
            PreferencesManager.SETTINGS_ROOM_SETTINGS_LABS_END_TO_END_IS_ACTIVE_PREFERENCE_KEY);

    cryptoIsEnabledPref.setEnabled(false);

    if (!mSession.isCryptoEnabled()) {
        useCryptoPref.setChecked(false);
        mLabsCategory.removePreference(cryptoIsEnabledPref);
    } else {
        mLabsCategory.removePreference(useCryptoPref);
    }

    useCryptoPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValueAsVoid) {
            if (TextUtils.isEmpty(mSession.getCredentials().deviceId)) {
                new AlertDialog.Builder(getActivity())
                        .setMessage(R.string.room_settings_labs_end_to_end_warnings)
                        .setPositiveButton(R.string.logout, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                                CommonActivityUtils.logout(getActivity());

                            }
                        }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                                useCryptoPref.setChecked(false);
                            }
                        }).setOnCancelListener(new DialogInterface.OnCancelListener() {
                            @Override
                            public void onCancel(DialogInterface dialog) {
                                dialog.dismiss();
                                useCryptoPref.setChecked(false);
                            }
                        }).create().show();
            } else {
                boolean newValue = (boolean) newValueAsVoid;

                if (mSession.isCryptoEnabled() != newValue) {
                    displayLoadingView();

                    mSession.enableCrypto(newValue, new ApiCallback<Void>() {
                        private void refresh() {
                            if (null != getActivity()) {
                                getActivity().runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        hideLoadingView();
                                        useCryptoPref.setChecked(mSession.isCryptoEnabled());

                                        if (mSession.isCryptoEnabled()) {
                                            mLabsCategory.removePreference(useCryptoPref);
                                            mLabsCategory.addPreference(cryptoIsEnabledPref);
                                        }
                                    }
                                });
                            }
                        }

                        @Override
                        public void onSuccess(Void info) {
                            useCryptoPref.setEnabled(false);
                            refresh();
                        }

                        @Override
                        public void onNetworkError(Exception e) {
                            useCryptoPref.setChecked(false);
                        }

                        @Override
                        public void onMatrixError(MatrixError e) {
                            useCryptoPref.setChecked(false);
                        }

                        @Override
                        public void onUnexpectedError(Exception e) {
                            useCryptoPref.setChecked(false);
                        }
                    });
                }
            }

            return true;
        }
    });

    // SaveMode Managment
    final CheckBoxPreference dataSaveModePref = (CheckBoxPreference) findPreference(
            PreferencesManager.SETTINGS_DATA_SAVE_MODE_PREFERENCE_KEY);
    dataSaveModePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            List<MXSession> sessions = Matrix.getMXSessions(getActivity());
            for (MXSession session : sessions) {
                session.setUseDataSaveMode((boolean) newValue);
            }

            return true;
        }
    });

    // Analytics tracking managment
    final CheckBoxPreference useAnalyticsModePref = (CheckBoxPreference) findPreference(
            PreferencesManager.SETTINGS_USE_ANALYTICS_KEY);

    // On if the analytics tracking is activated
    useAnalyticsModePref.setChecked(PreferencesManager.useAnalytics(appContext));

    useAnalyticsModePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            PreferencesManager.setUseAnalytics(appContext, (boolean) newValue);
            return true;
        }
    });

    // Rageshake Managment
    final CheckBoxPreference useRageShakeModePref = (CheckBoxPreference) findPreference(
            PreferencesManager.SETTINGS_USE_RAGE_SHAKE_KEY);
    final boolean mIsUsedRageShake = PreferencesManager.useRageshake(appContext);

    useRageShakeModePref.setChecked(mIsUsedRageShake);

    useRageShakeModePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            PreferencesManager.setUseRageshake(appContext, (boolean) newValue);
            return true;
        }
    });

    // deactivate account
    EditTextPreference deactivateAccountPref = (EditTextPreference) findPreference(
            PreferencesManager.SETTINGS_DEACTIVATE_ACCOUNT_KEY);

    if (null != deactivateAccountPref) {
        deactivateAccountPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                startActivity(DeactivateAccountActivity.Companion.getIntent(getActivity()));

                return false;
            }
        });
    }

    addButtons();
    refreshPushersList();
    refreshEmailsList();
    refreshPhoneNumbersList();
    refreshIgnoredUsersList();
    refreshDevicesList();
    refreshGroupFlairsList();
}