@Override
 public void onResume() {
   // TODO Auto-generated method stub
   super.onResume();
   //		setProfilePic();
   if (myNameView != null) myNameView.setText(sharedPrefManager.getDisplayName());
   setProfilePic(sharedPrefManager.getUserName());
   if (aboutSuperGroupView != null)
     aboutSuperGroupView.setText("About " + sharedPrefManager.getCurrentSGDisplayName());
 }
 private String getImagePath(String groupPicId) {
   if (groupPicId == null)
     groupPicId =
         SharedPrefManager.getInstance()
             .getUserFileId(
                 SharedPrefManager.getInstance().getUserName()); // 1_1_7_G_I_I3_e1zihzwn02
   if (groupPicId != null) {
     String profilePicUrl = groupPicId + ".jpg"; // AppConstants.media_get_url+
     File file = Environment.getExternalStorageDirectory();
     String filename = file.getPath() + File.separator + "SuperChat/" + profilePicUrl;
     File contentFile = new File(filename);
     if (contentFile != null && contentFile.exists()) {
       return filename;
     }
   }
   return null;
 }
 @Override
 protected void onPostExecute(String onlineVersion) {
   super.onPostExecute(onlineVersion);
   if (progressDialog != null) {
     progressDialog.dismiss();
     progressDialog = null;
   }
   String currentVersion = getCurrentAppVersion();
   SharedPrefManager iPrefManager = SharedPrefManager.getInstance();
   if (onlineVersion != null && !onlineVersion.isEmpty()) {
     if (!currentVersion.equals(onlineVersion)) {
       //	            	Toast.makeText(MoreScreen.this, "Updates is available.",
       // Toast.LENGTH_LONG).show();
       showUpdateDialog("Update Available!", "Do you want to update \"SuperChat\"?");
     } else {
       iPrefManager.setUpdateCheck(true);
       Toast.makeText(MoreScreen.this, "No updates available.", Toast.LENGTH_SHORT).show();
     }
   }
   //	        Log.d("update", "Current version " + currentVersion + "playstore version " +
   // onlineVersion);
 }
 @Override
 public void onReceive(Context context, Intent intent) {
   if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
     ConnectivityManager cm =
         (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
     NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
     boolean isConnected = activeNetwork != null && activeNetwork.isConnected();
     boolean isConnectingOrConnected =
         activeNetwork != null && activeNetwork.isConnectedOrConnecting();
     SharedPrefManager pref = SharedPrefManager.getInstance();
     if (pref != null) {
       String mobileNumber = pref.getUserPhone();
       if (mobileNumber == null || mobileNumber.equals("")) {
         System.out.println("mobileNumber == null, so returning......");
         return;
       }
     }
     ChatService.xmppConectionStatus = false;
     if (ChatService.connectionStatusListener != null)
       ChatService.connectionStatusListener.notifyConnectionChange();
     if (isConnected) {
       isConnectedCalled = true;
       context.startService(new Intent(SuperChatApplication.context, ChatService.class));
       context.startService(new Intent(SuperChatApplication.context, SinchService.class));
     } else {
       if (!isConnectedCalled && !isConnectingOrConnected) {
         SharedPrefManager.getInstance().saveLastOnline(System.currentTimeMillis());
       }
       //					ChatService.xmppConectionStatus = false;
       //					if(ChatService.connectionStatusListener!=null)
       //						ChatService.connectionStatusListener.notifyConnectionChange();
     }
     System.out.println(
         "XmppStateReceiver connectivity changed."
             + isConnectingOrConnected
             + " , "
             + isConnectingOrConnected);
   }
 }
  public void showSnoozeDialog() {
    final Dialog bteldialog = new Dialog(this);
    bteldialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    bteldialog.setCanceledOnTouchOutside(true);
    bteldialog.setContentView(R.layout.snooze_settings);
    TextView btn = ((TextView) bteldialog.findViewById(R.id.id_set_btn));
    final Spinner spinner = (Spinner) bteldialog.findViewById(R.id.spinner);
    sharedPrefManager.isSnoozeExpired(sharedPrefManager.getUserDomain());
    spinner.setSelection(sharedPrefManager.getSnoozeIndex(sharedPrefManager.getUserDomain()));
    btn.setOnTouchListener(
        new OnTouchListener() {

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            bteldialog.cancel();
            sharedPrefManager.setSnoozeIndex(
                sharedPrefManager.getUserDomain(), spinner.getSelectedItemPosition());
            sharedPrefManager.setSnoozeStartTime(
                sharedPrefManager.getUserDomain(), System.currentTimeMillis());
            muteSettingText.setVisibility(View.VISIBLE);
            muteSettingText.setText(String.valueOf(spinner.getSelectedItem()));
            //                Toast.makeText(MoreScreen.this,
            // String.valueOf(spinner.getSelectedItem()), Toast.LENGTH_SHORT).show();
            return false;
          }
        });
    TextView cancelBtn = ((TextView) bteldialog.findViewById(R.id.id_cancel));
    cancelBtn.setOnTouchListener(
        new OnTouchListener() {

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            bteldialog.cancel();
            return false;
          }
        });
    if (!bteldialog.isShowing()) bteldialog.show();
  }
  private boolean setProfilePic(String userName) {
    String picId = SharedPrefManager.getInstance().getUserFileId(userName);

    String img_path = getImagePath(picId);
    //		android.graphics.Bitmap bitmap = SuperChatApplication.getBitmapFromMemCache(groupPicId);
    ImageView picView = (ImageView) findViewById(R.id.id_profile_pic);
    //		if(SharedPrefManager.getInstance().getUserGender(userName).equalsIgnoreCase("female"))
    //			picView.setImageResource(R.drawable.female_default);
    //		else
    picView.setImageResource(R.drawable.profile_pic);
    if (picId == null) return false;
    //		if (bitmap != null) {
    //			picView.setImageBitmap(bitmap);
    //			String profilePicUrl = groupPicId+".jpg";//AppConstants.media_get_url+
    //			File file = Environment.getExternalStorageDirectory();
    //			String filename = file.getPath()+ File.separator + "SuperChat/"+profilePicUrl;
    //			picView.setTag(filename);
    //			return true;
    //		}else
    if (img_path != null) {
      File file1 = new File(img_path);
      //			Log.d(TAG, "PicAvailibilty: "+ Uri.parse(filename)+" , "+filename+" , "+file1.exists());
      if (file1.exists()) {
        picView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        //				picView.setImageURI(Uri.parse(img_path));
        setThumb((ImageView) picView, img_path, picId);
        return true;
      }
    } else {
      img_path = getThumbPath(picId);
      if (img_path != null) {
        File file1 = new File(img_path);
        //			Log.d(TAG, "PicAvailibilty: "+ Uri.parse(filename)+" , "+filename+" ,
        // "+file1.exists());
        if (file1.exists()) {
          picView.setScaleType(ImageView.ScaleType.CENTER_CROP);
          //				picView.setImageURI(Uri.parse(img_path));
          setThumb((ImageView) picView, img_path, picId);
        }
      }
    }
    if (picId != null && picId.equals("clear")) return true;
    return false;
  }
  private void setProfilePic() {
    if (ProfileScreen.oldImageFileId != null) {
      String currentFileId =
          SharedPrefManager.getInstance()
              .getUserFileId(SharedPrefManager.getInstance().getUserName());
      if (currentFileId != null && !ProfileScreen.oldImageFileId.equals(currentFileId)) {
        SharedPrefManager.getInstance()
            .saveUserFileId(
                SharedPrefManager.getInstance().getUserName(), ProfileScreen.oldImageFileId);
      }
    }
    String groupPicId =
        SharedPrefManager.getInstance()
            .getUserFileId(
                SharedPrefManager.getInstance().getUserName()); // 1_1_7_G_I_I3_e1zihzwn02
    android.graphics.Bitmap bitmap = SuperChatApplication.getBitmapFromMemCache(groupPicId);
    if (groupPicId != null && !groupPicId.equals("clear")) {
      String profilePicUrl = groupPicId + ".jpg"; // AppConstants.media_get_url+
      File file = Environment.getExternalStorageDirectory();
      //		if(groupPicId != null && groupPicId.length() > 0 && groupPicId.lastIndexOf('/')!=-1)
      //			profilePicUrl += groupPicId.substring(groupPicId.lastIndexOf('/'));

      String filename = file.getPath() + File.separator + "SuperChat/" + profilePicUrl;
      File file1 = new File(filename);
      //		Log.d(TAG, "PicAvailibilty: "+ Uri.parse(filename)+" , "+filename+" , "+file1.exists());
      if (bitmap != null) {
        //			profileIconView.setImageBitmap(bitmap);
      } else if (file1.exists()) {
        //			profileIconView.setImageURI(Uri.parse(filename));
        //			profileIconView.setBackgroundDrawable(null);

        //			 Bitmap myBitmap = BitmapFactory.decodeFile(filename);
        //			    Drawable drawable = new BitmapDrawable(getResources(), myBitmap);
        //			    profileIconView.setBackgroundDrawable(drawable);
      }
    } else {
      //		profileIconView.setImageDrawable(null);
      //		profileIconView.setBackgroundResource(R.drawable.about_icon);
    }
  }
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.more_screen);

    UtilSetFont.setFontMainScreen(this);

    profileIconLayout = (RelativeLayout) findViewById(R.id.id_profile_layout);
    //		advancedSettings = (RelativeLayout)findViewById(R.id.id_advanced_settings);
    //		sharedID = (RelativeLayout)findViewById(R.id.id_shared);
    //		accountIconLayout = (LinearLayout)view.findViewById(R.id.id_account_layout);
    //		settingIconLayout = (LinearLayout)view.findViewById(R.id.id_setting_layout);
    myNameView = (TextView) findViewById(R.id.id_my_name);
    aboutSuperGroupView = (TextView) findViewById(R.id.id_about_supergroup);
    aboutIconLayout = (RelativeLayout) findViewById(R.id.id_about_us);
    blockListLayout = (RelativeLayout) findViewById(R.id.id_block_list_layout);
    feedbackLayout = (RelativeLayout) findViewById(R.id.id_feedback_layout);
    consolePassLayout = (RelativeLayout) findViewById(R.id.id_configure_console_pass);
    id_open_console = (RelativeLayout) findViewById(R.id.id_open_console);
    sgProfileLayout = (RelativeLayout) findViewById(R.id.id_supergroup_profile);
    privacyLayout = (RelativeLayout) findViewById(R.id.id_privacy_layout);

    checkUpdateLayout = (RelativeLayout) findViewById(R.id.id_checkupdate_layout);
    soonzeLayout = (RelativeLayout) findViewById(R.id.id_snooze_layout);
    muteSettingText = (TextView) findViewById(R.id.mute_setting_txt);
    id_data_usage_layout = (RelativeLayout) findViewById(R.id.id_data_usage_layout);
    switchSaveGalleryMedia = (Switch) findViewById(R.id.switchSaveGalleryMedia);

    superGroupDownloadSettingsHandler = new SuperGroupDownloadSettingsHandler(this);

    boolean isSaveInGallery = superGroupDownloadSettingsHandler.isSavedInGallery();
    switchSaveGalleryMedia.setChecked(isSaveInGallery);

    switchSaveGalleryMedia.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            superGroupDownloadSettingsHandler.changeMediaGallerySetting(isChecked);
          }
        });

    officialIDLayout = (RelativeLayout) findViewById(R.id.id_offocial_id_layout);
    memberStatsLayout = (RelativeLayout) findViewById(R.id.id_memberstats_layout);
    privacyLayout.setOnClickListener(this);
    id_data_usage_layout.setOnClickListener(this);
    soonzeLayout.setOnClickListener(this);
    ((RelativeLayout) findViewById(R.id.id_chat_layout)).setOnClickListener(this);
    sharedPrefManager = SharedPrefManager.getInstance();
    myNameView.setText(sharedPrefManager.getDisplayName());
    aboutSuperGroupView.setText("About " + sharedPrefManager.getCurrentSGDisplayName());
    if (sharedPrefManager.isDomainAdmin(sharedPrefManager.getUserDomain())
        || sharedPrefManager.isDomainSubAdmin(sharedPrefManager.getUserDomain())) {
      //			memberStatsLayout = (RelativeLayout)findViewById(R.id.id_member_stats_layout);
      advancedSettings = (RelativeLayout) findViewById(R.id.id_advanced_settings);
      memberManageLayout = (RelativeLayout) findViewById(R.id.id_manage_members_layout);
      //			memberStatsLayout.setVisibility(View.VISIBLE);
      memberManageLayout.setVisibility(View.VISIBLE);
      //            advancedSettings.setVisibility(View.VISIBLE);
      officialIDLayout.setVisibility(View.VISIBLE);
      memberStatsLayout.setVisibility(View.VISIBLE);
      //			consolePassLayout.setVisibility(View.VISIBLE);
      advancedSettings.setOnClickListener(this);
      officialIDLayout.setOnClickListener(this);
      memberStatsLayout.setOnClickListener(this);
      memberManageLayout.setOnClickListener(this);
    }
    if ((sharedPrefManager.getSnoozeExpiryTime(sharedPrefManager.getUserDomain())
            - System.currentTimeMillis())
        > 0) {
      String time =
          (getResources().getStringArray(R.array.snooze_list_array))
              [sharedPrefManager.getSnoozeIndex(sharedPrefManager.getUserDomain())];
      muteSettingText.setVisibility(View.VISIBLE);
      muteSettingText.setText(time);
    }
    ((ImageView) findViewById(R.id.id_profile_pic))
        .setOnClickListener(
            new OnClickListener() {

              @Override
              public void onClick(View v) {
                // TODO Auto-generated method stub
                String file_path =
                    getImagePath(
                        SharedPrefManager.getInstance()
                            .getUserFileId(sharedPrefManager.getUserName()));
                if (file_path == null || (file_path != null && file_path.trim().length() == 0))
                  file_path = getImagePath(null);

                if (file_path != null) {
                  Intent intent = new Intent();
                  intent.setAction(Intent.ACTION_VIEW);
                  if (file_path.startsWith("http://"))
                    intent.setDataAndType(Uri.parse(file_path), "image/*");
                  else intent.setDataAndType(Uri.parse("file://" + file_path), "image/*");
                  startActivity(intent);
                }
              }
            });
    //		profileIconView = (RoundedImageView)view.findViewById(R.id.id_profile_icon);
    ((TextView) findViewById(R.id.id_back))
        .setOnClickListener(
            new OnClickListener() {

              @Override
              public void onClick(View v) {
                // TODO Auto-generated method stub
                finish();
              }
            });
    ImageView xmppStatusView = (ImageView) findViewById(R.id.id_xmpp_status);

    if (ChatService.xmppConectionStatus) {
      xmppStatusView.setImageResource(R.drawable.blue_dot);
    } else {
      xmppStatusView.setImageResource(R.drawable.red_dot);
    }

    //		settingIconLayout.setOnClickListener(this);
    blockListLayout.setOnClickListener(this);
    feedbackLayout.setOnClickListener(this);
    consolePassLayout.setOnClickListener(this);
    id_open_console.setOnClickListener(this);
    profileIconLayout.setOnClickListener(this);
    //		sharedID.setOnClickListener(this);
    //		accountIconLayout.setOnClickListener(this);
    sgProfileLayout.setVisibility(View.VISIBLE);
    sgProfileLayout.setOnClickListener(this);
    checkUpdateLayout.setOnClickListener(this);
    aboutIconLayout.setOnClickListener(this);

    //		Tracker t = ((SuperChatApplication)
    // SuperChatApplication.context).getTracker(TrackerName.APP_TRACKER);
    //        t.setScreenName("More Options Screen");
    //        t.send(new HitBuilders.AppViewBuilder().build());
    //		setProfilePic(sharedPrefManager.getUserName());

    UtilSetFont.setFontMainScreen(this);
  }