Android Open Source - PicSync Rename Folder Activity






From Project

Back to project page PicSync.

License

The source code is released under:

Apache License

If you think the Android project PicSync listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.darrenmowat.gdcu.activity;
// www .j ava  2 s .  co m
import java.io.IOException;

import org.json.JSONException;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.darrenmowat.gdcu.GDCU;
import com.darrenmowat.gdcu.R;
import com.darrenmowat.gdcu.data.Preferences;
import com.darrenmowat.gdcu.service.MediaService;
import com.darrenmowat.gdcu.tasks.RenameFolderTask;
import com.darrenmowat.gdcu.ui.ProgressDialogFragment;
import com.google.api.services.drive.model.File;

public class RenameFolderActivity extends SherlockFragmentActivity {

  private EditText newNameET;
  private RenameFolderTask mTask;
  
  private ProgressDialogFragment progressFragment;
  
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_rename_folder_activtiy);

    newNameET = (EditText) findViewById(R.id.renameFolderEditText);
    
    final String currentName = Preferences.getUploadsFolderName(RenameFolderActivity.this);

    newNameET.getText().append(currentName);
    
    Button renameButton = (Button) findViewById(R.id.renameFolderButton);
    renameButton.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View v) {
        final Context context = RenameFolderActivity.this;
        String newName = newNameET.getText().toString();
        if (isValidName(newName)) {
          String token = GDCU.getGDCU(context).getUserToken();
          mTask = new RenameFolderTask(RenameFolderActivity.this, token, currentName, newName);
          mTask.execute();
          showProgressFragment();
        } else {
          Toast.makeText(RenameFolderActivity.this, "Invalid folder name",
              Toast.LENGTH_SHORT).show();
        }

      }

    });
  }

  private boolean isValidName(String name) {
    return true;
  }
  
  public void onDone(final File newUploads) {
    final Activity activity = RenameFolderActivity.this;
    activity.runOnUiThread(new Runnable() {

      @Override
      public void run() {
        removeProgressFragment();
        Toast.makeText(RenameFolderActivity.this, "Renamed to " + newUploads.getTitle(),
            Toast.LENGTH_SHORT).show();
        Intent service = new Intent(activity, MediaService.class);
        service.setAction(MediaService.NO_WAIT);
        activity.startService(service);
      }
      
    });
  }

  public void onIOException(final IOException e) {
    final Activity activity = RenameFolderActivity.this;
    activity.runOnUiThread(new Runnable() {

      @Override
      public void run() {
        removeProgressFragment();
        Toast.makeText(RenameFolderActivity.this, "IOException " + e.getMessage(),
            Toast.LENGTH_SHORT).show();
      }
      
    });
  }
  
  public void onJSONException(final JSONException e) {
    final Activity activity = RenameFolderActivity.this;
    activity.runOnUiThread(new Runnable() {

      @Override
      public void run() {
        removeProgressFragment();
        Toast.makeText(RenameFolderActivity.this, "JSONException " + e.getMessage(),
            Toast.LENGTH_SHORT).show();
      }
      
    });
  }
  
  private void removeProgressFragment() {
    if (progressFragment != null) {
      FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
      ft.remove(progressFragment);
      ft.commit();
      progressFragment = null;
    }
  }
  
  private void showProgressFragment() {
    if(progressFragment == null) { 
    progressFragment = ProgressDialogFragment.newInstance(getResources().getString(
        R.string.rename_progress));
    progressFragment.setCancelable(false);
    progressFragment.show(getSupportFragmentManager(), "renamingProgressDialog");
    }
  }
  
}




Java Source Code List

com.darrenmowat.gdcu.GDCU.java
com.darrenmowat.gdcu.Keys.java
com.darrenmowat.gdcu.activity.AuthActivity.java
com.darrenmowat.gdcu.activity.RenameFolderActivity.java
com.darrenmowat.gdcu.activity.SettingsActivity.java
com.darrenmowat.gdcu.activity.WebviewActivity.java
com.darrenmowat.gdcu.data.Database.java
com.darrenmowat.gdcu.data.Preferences.java
com.darrenmowat.gdcu.drive.DriveApi.java
com.darrenmowat.gdcu.otto.DataBus.java
com.darrenmowat.gdcu.otto.UploadStatusEventProducer.java
com.darrenmowat.gdcu.otto.UploadStatusEvent.java
com.darrenmowat.gdcu.security.PackageSecurityException.java
com.darrenmowat.gdcu.security.PackageSecurity.java
com.darrenmowat.gdcu.service.GalleryAlarmListener.java
com.darrenmowat.gdcu.service.GalleryObserver.java
com.darrenmowat.gdcu.service.MediaService.java
com.darrenmowat.gdcu.service.MediaThread.java
com.darrenmowat.gdcu.service.Notifier.java
com.darrenmowat.gdcu.service.ServiceUtils.java
com.darrenmowat.gdcu.service.UploadService.java
com.darrenmowat.gdcu.service.UploadThread.java
com.darrenmowat.gdcu.service.helpers.CloudSyncer.java
com.darrenmowat.gdcu.service.helpers.Media.java
com.darrenmowat.gdcu.service.helpers.ServiceIntents.java
com.darrenmowat.gdcu.service.helpers.ThreadCallbacks.java
com.darrenmowat.gdcu.tasks.GetTokenTask.java
com.darrenmowat.gdcu.tasks.RenameFolderTask.java
com.darrenmowat.gdcu.ui.ProgressDialogFragment.java
com.darrenmowat.gdcu.utils.HexConversions.java
com.darrenmowat.gdcu.utils.MD5Utils.java
com.darrenmowat.gdcu.utils.Preconditions.java