Пример #1
0
  @Override
  public void onClick(View v) {
    switch (v.getId()) {
      case R.id.btn_logout: // 退出登录
        logout();
        break;
      case R.id.layout_help_instructions: // 帮助说明
        Intent intent = new Intent(SettingsActivity.this, HelpActivity.class);
        startActivity(intent);
        break;

      case R.id.layout_cache_clear:
        boolean isDeleted =
            FileUtil.deleteDirFromSD(
                Environment.getExternalStorageDirectory().getAbsolutePath() + "/.truelove2");
        if (isDeleted) {
          showToast("缓存已清除");
          //	    mTvCacheSize.setText((int)
          // (FileUtil.getDirSize(Environment.getExternalStorageDirectory().getAbsolutePath() +
          // "/.truelove2") / 1024.0f) + "kb");
          mTvCacheSize.setText(
              String.format(
                      "%.2f",
                      (FileUtil.getDirSize(
                              Environment.getExternalStorageDirectory().getAbsolutePath()
                                  + "/.truelove2")
                          / 1024.0f
                          / 1024))
                  + "mb");
        }
        break;
    }
  }
  @LargeTest
  public void testExtraVideoQuality() throws Exception {
    mFile = new File(Environment.getExternalStorageDirectory(), "video.tmp");
    mFile2 = new File(Environment.getExternalStorageDirectory(), "video2.tmp");

    Uri uri = Uri.fromFile(mFile);
    mIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
    mIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0); // low quality
    setActivityIntent(mIntent);
    getActivity();

    recordVideo();
    pressDone();

    verify(getActivity(), uri);
    setActivity(null);

    uri = Uri.fromFile(mFile2);
    mIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
    mIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); // high quality
    setActivityIntent(mIntent);
    getActivity();

    recordVideo();
    pressDone();

    verify(getActivity(), uri);
    assertTrue(mFile.length() <= mFile2.length());
  }
Пример #3
0
  public IOReport() {
    this.stringBuilder = new StringBuilder();
    Date date = new Date();
    SimpleDateFormat format1 = new SimpleDateFormat("dd.MM.yyyy_hh:mm");
    format = format1.format(date);
    this.fileDestination =
        new File(
            Environment.getExternalStorageDirectory() + "/Robotium-Screenshots/report_" + format);
    fileDestination.mkdirs();
    this.fileDestination =
        new File(
            Environment.getExternalStorageDirectory()
                + "/Robotium-Screenshots/report_"
                + format
                + "/img");
    fileDestination.mkdirs();

    this.fileDestination =
        new File(
            Environment.getExternalStorageDirectory()
                + "/Robotium-Screenshots/report_"
                + format
                + "/index.html");
    try {
      fileDestination.createNewFile();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  private void getAvailableMissionList() {
    try {
      File missionFolder = new File(Environment.getExternalStorageDirectory() + "/Mission Files");
      // gets a list of the files
      File[] sdDirList = missionFolder.listFiles();

      String missionTitle;
      String missionDesc;
      String pBest;
      File fileToHandle;
      for (int i = 0; i < sdDirList.length; i++) {
        fileToHandle =
            new File(
                Environment.getExternalStorageDirectory()
                    + "/Mission Files/"
                    + sdDirList[i].getName());
        String params = ReadFileContents(fileToHandle);
        String[] tokenized = params.split("\n");
        missionTitle = tokenized[0];
        missionDesc = tokenized[1];
        pBest = "N/K";
        availableMissions.add(
            new MissionSummary(missionTitle, missionDesc, pBest, fileToHandle.getName(), this));
      }
    } catch (NullPointerException e) {
      availableMissions.add(
          new MissionSummary(
              "No missions found", "Click here to download new missions", "", "N/A", this));
    }
  }
  public void onClick(View v) {
    if (v.getId() == R.id.browse) {
      boolean mExternalStorageAvailable = false;
      String state = Environment.getExternalStorageState();

      if (Environment.MEDIA_MOUNTED.equals(state)
          || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        mExternalStorageAvailable = true;
      } else {
        mExternalStorageAvailable = false;
      }

      if (mExternalStorageAvailable) {
        System.out.println(Environment.getExternalStorageDirectory().toString());
        Log.d(TAG, Environment.getExternalStorageDirectory().toString());

        mPath = new File(Environment.getExternalStorageDirectory().toString());
        Log.d(TAG, mPath.toString());
        mFileList = mPath.list();
        onCreateDialog(AWS_APP_FILE_SELECT_DIALOG);
      }
    } else if (v.getId() == R.id.upload) {
      /* Switch to File List view */
      Intent i = new Intent(getApplicationContext(), AwsAppGetFileListActivity.class);
      startActivity(i);
    }
  }
Пример #6
0
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // To Do
    if (requestCode == 0) {
      if (resultCode == RESULT_OK) {
        Bitmap bm = (Bitmap) data.getExtras().getParcelable("data");
        // imageButton.setImageBitmap(bm);
        // textView.setText("Photo OK");

        // Save picture
        String imagepath = Environment.getExternalStorageDirectory().getAbsolutePath();
        URI uri = new URI(Environment.getExternalStorageDirectory().getAbsolutePath());
        Intent intent = new Intent(MediaStore.EXTRA_OUTPUT, uri);

        // Get screen dimensions
        DisplayMetrics display = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(display);
        int screenWidth = display.widthPixels;
        int screenHeight = display.heightPixels;

        // Scale image
        Bitmap bm_scaled;
        Boolean filter = true;
        bm_scaled = Bitmap.createScaledBitmap(bm, screenWidth, 2 * screenHeight / 3, filter);
        imageButton.setImageBitmap(bm_scaled);
        textView.setText("Photo OK");

      } else if (resultCode == RESULT_CANCELED) {
        textView.setText("Photo Canceled");
      } else {
        textView.setText("Not sure what happened.");
      }
    }
  }
Пример #7
0
    @Override
    public void onEvent(int event, String path) {
      // TODO Auto-generated method stub

      /** 监听到文件创建活动 */

      /** 如果是对SD根目录下的操作 */
      if (path != null) {

        File f = new File(Environment.getExternalStorageDirectory().getPath() + "/" + path);
        if (!f.exists() && SD_Files.contains(path)) {
          /** 如果文件不存在了,也就是说文件被删除了,那么从名单中删除 */
          SD_Files.remove(path);
          System.out.println("delete file :" + path);
          return;
        } else if (!SD_Files.contains(path)) {
          /** 原来的文件目录中不包含这个文件名称,说明这是一个新创建的文件 */
          SD_Files.add(path);
          System.out.println("create file :" + path);
          deletePath = new String(Environment.getExternalStorageDirectory().getPath() + "/" + path);
          ResultMsg =
              new String(
                  "SD根目录下有新文件创建:\n /sdcard/"
                      + path
                      + "\n如果您不希望应用程序更改您SD根目录下的文件内容,您可以通过删除按钮删除这个文件夹。");
          handler.post(showSD_Info);
        }
      }
    }
Пример #8
0
  public void backup() {
    Process process = null;
    DataOutputStream os = null;

    try {
      process = Runtime.getRuntime().exec("su");
      os = new DataOutputStream(process.getOutputStream());
      os.writeBytes("mount -o remount,rw /system\n");
      os.writeBytes(
          "cp -f /system/build.prop "
              + Environment.getExternalStorageDirectory().getAbsolutePath()
              + "/build.prop.bak\n");
      os.writeBytes("mount -o remount,ro /system\n");
      os.writeBytes("exit\n");
      os.flush();
      process.waitFor();
    } catch (Exception e) {
      log("Error in backup: " + e.getMessage());
    } finally {
      try {
        if (os != null) {
          os.close();
        }
        process.destroy();
      } catch (Exception e) {
        log("Error in closing backup process: " + e.getMessage());
      }
    }

    log(
        "build.prop Backup at "
            + Environment.getExternalStorageDirectory().getAbsolutePath()
            + "/build.prop.bak");
  }
Пример #9
0
  public GenerXml(String ActivityName, boolean loop) {
    int filenum = 0;
    String fileName = ActivityName;

    File dir = new File(Environment.getExternalStorageDirectory() + "/GetInfoFile/");
    String[] dirs = dir.list();
    filenum = dirs.length;
    int num = 0;
    for (String temp : dirs) {
      if (temp.contains(ActivityName)) {
        num = num + 1;
      }
    }
    fileName = ActivityName + "_" + num;

    try {
      fileoutputstream =
          new FileOutputStream(
              Environment.getExternalStorageDirectory()
                  + "/GetInfoFile/"
                  + (filenum > 9 ? filenum : ("0" + filenum))
                  + "_"
                  + fileName
                  + ".xml");
      filename = (filenum > 9 ? filenum : ("0" + filenum)) + "_" + fileName;
      printStream = new PrintStream(fileoutputstream);
      printStream.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
      printStream.println("<Activity>");
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Пример #10
0
  @NonNull
  public static synchronized RomInformation[] getRoms(Context context) {
    RomInformation[] roms = new RomInformation[0];

    try {
      roms = MbtoolSocket.getInstance().getInstalledRoms(context);

      for (RomInformation rom : roms) {
        rom.setThumbnailPath(
            Environment.getExternalStorageDirectory()
                + "/MultiBoot/"
                + rom.getId()
                + "/thumbnail.webp");
        rom.setWallpaperPath(
            Environment.getExternalStorageDirectory()
                + "/MultiBoot/"
                + rom.getId()
                + "/wallpaper.webp");
        rom.setConfigPath(
            Environment.getExternalStorageDirectory()
                + "/MultiBoot/"
                + rom.getId()
                + "/config.json");
        rom.setImageResId(R.drawable.rom_android);
        rom.setDefaultName(getDefaultName(context, rom));

        loadConfig(rom);
      }
    } catch (IOException e) {
      Log.e(TAG, "mbtool communication error", e);
    }

    return roms;
  }
Пример #11
0
public class CONSTANTS {

  public static final String METADATA_REQUEST_BUNDLE_TAG = "requestMetaData";
  public static final String FILE_START_NAME = "VMS_";
  public static final String VIDEO_EXTENSION = ".mp4";
  public static final String IMAGE_EXTENSION = ".jpg";
  public static final String DCIM_FOLDER = "/DCIM";
  public static final String CAMERA_FOLDER = "/video";
  public static final String TEMP_FOLDER = "/Temp";
  public static final String CAMERA_FOLDER_PATH =
      Environment.getExternalStorageDirectory().toString()
          + CONSTANTS.DCIM_FOLDER
          + CONSTANTS.CAMERA_FOLDER;
  public static final String TEMP_FOLDER_PATH =
      Environment.getExternalStorageDirectory().toString()
          + CONSTANTS.DCIM_FOLDER
          + CONSTANTS.CAMERA_FOLDER
          + CONSTANTS.TEMP_FOLDER;
  public static final String VIDEO_CONTENT_URI = "content://media/external/video/media";

  public static final String KEY_DELETE_FOLDER_FROM_SDCARD = "deleteFolderFromSDCard";

  public static final String RECEIVER_ACTION_SAVE_FRAME =
      "com.javacv.recorder.intent.action.SAVE_FRAME";
  public static final String RECEIVER_CATEGORY_SAVE_FRAME = "com.javacv.recorder";
  public static final String TAG_SAVE_FRAME = "saveFrame";

  public static final int RESOLUTION_HIGH = 1300;
  public static final int RESOLUTION_MEDIUM = 500;
  public static final int RESOLUTION_LOW = 180;

  public static final int RESOLUTION_HIGH_VALUE = 2;
  public static final int RESOLUTION_MEDIUM_VALUE = 1;
  public static final int RESOLUTION_LOW_VALUE = 0;
}
Пример #12
0
  private void copyAssets() {

    InputStream in = null;
    OutputStream out = null;
    try {

      in = getAssets().open("tiles.zip");

      Log.i(TAG, ": " + Environment.getExternalStorageDirectory());
      File dir = new File(Environment.getExternalStorageDirectory(), "osmdroid");
      File wallpaperDirectory = new File("/osmdroid/tiles/");
      File folder =
          new File(Environment.getExternalStorageDirectory().toString() + "/osmdroid/tiles/");
      folder.mkdirs();
      Log.i(TAG, "isExist : " + folder.exists());
      if (!folder.exists()) folder.mkdirs();
      File fileZip = new File(folder, "tiles.zip");
      Log.i(TAG, "isExist : " + fileZip.exists());

      out = new FileOutputStream(fileZip);
      copyFile(in, out);
      in.close();
      unzip(fileZip, folder);
      in = null;
      out.flush();
      out.close();
      out = null;
    } catch (IOException e) {
      Log.e("tag", "Failed to copy asset file: " + e.getMessage());
    }
  }
Пример #13
0
/** Created by mrpan on 15/12/6. */
public class Config {

  /**
   * 是否只在wifi 下使用 的key
   *
   * <p>values 1 表示 仅在wifi下使用 values 0 表示 都可以使用
   */
  public static String TYPE_CONN = "TYPE_CONN";

  public static int TYPE_ALL = 0;
  public static int TYPE_WIFI = 1;
  public static String DIR_PATH =
      Environment.getExternalStorageDirectory().toString() + "/AnnHome/Cache/";
  public static String DIR_IMAGE_PATH =
      Environment.getExternalStorageDirectory().toString() + "/AnnHome/Image/";
  public static String DIR_DATABASE_PATH =
      Environment.getExternalStorageDirectory().toString() + "AnnHome/DataBase/";
  public static final int DATA_SHOW = 0012;
  public static final int NET_ERROR = 0013;
  public static final int SHOW_NEXT = 0011;
  public static final int CACHE_DATA_SHOW = 0014;
  public static final int SHOW_AD = 0015;

  public static final int CLEAR_CACHE = 0015;

  public static final int HTTP_REQUEST_SUCCESS = 1001;
  public static final int HTTP_REQUEST_ERROR = 1002;
}
Пример #14
0
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = getActivity().getLayoutInflater();
    final View view = (View) inflater.inflate(R.layout.dialog_tox_id, null);
    builder.setView(view);
    builder.setNeutralButton(
        getString(R.string.button_ok),
        new Dialog.OnClickListener() {
          public void onClick(DialogInterface dialogInterface, int ID) {
            mListener.onDialogClick(DialogToxID.this);
          }
        });

    /* Generate or load QR image of Tox ID */
    File file = new File(Environment.getExternalStorageDirectory().getPath() + "/Antox/");
    if (!file.exists()) {
      file.mkdirs();
    }

    File noMedia =
        new File(Environment.getExternalStorageDirectory().getPath() + "/Antox/", ".nomedia");
    if (!noMedia.exists()) {
      try {
        noMedia.createNewFile();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }

    file = new File(Environment.getExternalStorageDirectory().getPath() + "/Antox/userkey_qr.png");
    SharedPreferences pref =
        PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
    generateQR(pref.getString("tox_id", ""));
    Bitmap bmp = BitmapFactory.decodeFile(file.getAbsolutePath());

    ImageButton qrCode = (ImageButton) view.findViewById(R.id.qr_image);
    qrCode.setImageBitmap(bmp);
    qrCode.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent shareIntent = new Intent();
            shareIntent.setAction(Intent.ACTION_SEND);
            shareIntent.putExtra(
                Intent.EXTRA_STREAM,
                Uri.fromFile(
                    new File(
                        Environment.getExternalStorageDirectory().getPath()
                            + "/Antox/userkey_qr.png")));
            shareIntent.setType("image/jpeg");
            view.getContext()
                .startActivity(
                    Intent.createChooser(
                        shareIntent, getResources().getString(R.string.share_with)));
          }
        });

    return builder.create();
  }
Пример #15
0
  private void saveButtonClickedPublic() {

    Log.v("slim", "public folder path = " + Environment.getExternalStorageDirectory());

    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {

      try {
        String filePath =
            Environment.getExternalStorageDirectory() + File.separator + "filename.txt";
        File file = new File(filePath);
        PrintWriter out = new PrintWriter(file);
        out.println("test write file android " + System.currentTimeMillis());
        out.close();
        // Solution 1
        // getActivity().runOnUiThread(new Runnable() {
        //    @Override
        //    public void run() {
        //        mTextView.setText("sauvegarde terminée");
        //    }
        // });
        // Solution 2
        mHandler.post(
            new Runnable() {
              @Override
              public void run() {
                mTextView.setText("sauvegarde terminée");
              }
            });

      } catch (FileNotFoundException e) {
        e.printStackTrace();
      }
    }
  }
Пример #16
0
  public static String getSDCardPath() {
    String cmd = "cat /proc/mounts";
    Runtime run = Runtime.getRuntime(); // 返回与当前 Java 应用程序相关的运行时对象
    try {
      Process p = run.exec(cmd); // 启动另一个进程来执行命令
      BufferedInputStream in = new BufferedInputStream(p.getInputStream());
      BufferedReader inBr = new BufferedReader(new InputStreamReader(in));

      String lineStr;
      while ((lineStr = inBr.readLine()) != null) {
        // 获得命令执行后在控制台的输出信息
        //	            	Log.i("CommonUtil:getSDCardPath", lineStr);
        if (lineStr.contains("sdcard") && lineStr.contains(".android_secure")) {
          String[] strArray = lineStr.split(" ");
          if (strArray != null && strArray.length >= 5) {
            String result = strArray[1].replace("/.android_secure", "");
            return result;
          }
        }
        // 检查命令是否执行失败。
        if (p.waitFor() != 0 && p.exitValue() == 1) {
          // p.exitValue()==0表示正常结束,1:非正常结束
          Log.e("CommonUtil:getSDCardPath", "命令执行失败!");
        }
      }
      inBr.close();
      in.close();
    } catch (Exception e) {
      //	            Log.e("CommonUtil:getSDCardPath", e.toString());

      return Environment.getExternalStorageDirectory().getPath();
    }

    return Environment.getExternalStorageDirectory().getPath();
  }
Пример #17
0
  public void onClickCaptureBtn(View v) {

    try {
      String dirName = "YouAndI_Dir";
      SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");

      String imgName = format.format(new Date());

      File sdCardPath = Environment.getExternalStorageDirectory();
      File dirs = new File(sdCardPath, dirName);

      if (!dirs.exists()) {
        dirs.mkdirs();
      }

      capLayout.buildDrawingCache();
      Bitmap captureView = capLayout.getDrawingCache();

      File img = new File(sdCardPath.getAbsolutePath() + "/" + dirName + "/" + imgName + ".jpeg");

      FileOutputStream fos = new FileOutputStream(img);

      captureView.compress(Bitmap.CompressFormat.JPEG, 100, fos);
      sendBroadcast(
          new Intent(
              Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
              Uri.parse("file://" + Environment.getExternalStorageDirectory())));

      shareImge(img);

    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Пример #18
0
    public void scanForExistingVideosAndImport() {
      boolean mExternalStorageAvailable = false;
      boolean mExternalStorageWriteable = false;
      File rootfolder = Environment.getExternalStorageDirectory();

      String state = Environment.getExternalStorageState();
      if (Environment.MEDIA_MOUNTED.equals(state)) {
        mExternalStorageAvailable = mExternalStorageWriteable = true;
      } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        mExternalStorageAvailable = true;
        mExternalStorageWriteable = false;
      } else {
        mExternalStorageAvailable = mExternalStorageWriteable = false;
      }

      // OK, start
      if (mExternalStorageAvailable) {
        Log.d(
            TAG,
            "Starting import. OUR Directory path is : "
                + Environment.getExternalStorageDirectory().getAbsolutePath()
                + res.getString(R.string.rootSDcardFolder));
        directoryScanRecurse(rootfolder);
      }

      Log.d(TAG, " Import FINISHED !");
    }
Пример #19
0
  public void makeTemp() {
    Process process = null;
    DataOutputStream os = null;

    try {
      process = Runtime.getRuntime().exec("su");
      os = new DataOutputStream(process.getOutputStream());
      os.writeBytes("mount -o remount,rw /system\n");
      os.writeBytes(
          "cp -f /system/build.prop "
              + Environment.getExternalStorageDirectory().getAbsolutePath()
              + "/buildprop.tmp\n");
      os.writeBytes(
          "chmod 777 "
              + Environment.getExternalStorageDirectory().getAbsolutePath()
              + "/buildprop.tmp\n");
      os.writeBytes("mount -o remount,ro /system\n");
      os.writeBytes("exit\n");
      os.flush();
      process.waitFor();
    } catch (Exception e) {
      log("Error in making temp file: " + e.getMessage());
    } finally {
      try {
        if (os != null) {
          os.close();
        }
        process.destroy();
      } catch (Exception e) {
        log("Error in closing temp process: " + e.getMessage());
      }
    }

    tempFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/buildprop.tmp";
  }
Пример #20
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);

    photo = new File(Environment.getExternalStorageDirectory() + "/Frutarre_NoFrames");
    Log.d("GCM", photo.toString());
    boolean success = false;
    if (!photo.exists()) {
      success = photo.mkdirs();
    }
    // if (!success)
    {
      Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
      photo =
          new File(
              Environment.getExternalStorageDirectory() + "/Frutarre_NoFrames",
              Commons.getTodaysDate() + ".jpg");
      Log.d("GCM", photo.toString());
      intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
      Uri imageUir = Uri.fromFile(photo);
      startActivityForResult(intent, REQUEST_CODE);
      // finish();
    }
  }
  public void startAnimation() {
    if (item == null) {
      return;
    }

    foregroundImage = new ImageView(context);
    if (item.getForeground().getColor() != null) {
      foregroundImage.setBackgroundColor(Color.parseColor(item.getForeground().getColor()));
    }

    if (item.getForeground().getImage() != null) {
      try {
        FileInputStream fileInputStream =
            new FileInputStream(
                Environment.getExternalStorageDirectory() + File.separator + "1.png");
        Bitmap bitmap = BitmapFactory.decodeStream(fileInputStream);
        foregroundImage.setImageBitmap(bitmap);
      } catch (IOException e) {
        Log.e(TAG, e.getMessage(), e);
      }
    }

    AbsoluteLayout.LayoutParams foregroundParams =
        new AbsoluteLayout.LayoutParams(
            item.getGeometry().getWidth(), item.getGeometry().getHeight(),
            item.getGeometry().getLeft(), item.getGeometry().getTop());
    foregroundImage.setLayoutParams(foregroundParams);
    layout.addView(foregroundImage);

    backgroundImage = new ImageView(context);
    if (item.getBackground().getColor() != null) {
      backgroundImage.setBackgroundColor(Color.parseColor(item.getBackground().getColor()));
    }

    if (item.getBackground().getImage() != null) {
      try {
        FileInputStream fileInputStream =
            new FileInputStream(
                Environment.getExternalStorageDirectory() + File.separator + "1.png");
        Bitmap bitmap = BitmapFactory.decodeStream(fileInputStream);
        backgroundImage.setImageBitmap(bitmap);
      } catch (IOException e) {
        Log.e(TAG, e.getMessage(), e);
      }
    }

    AbsoluteLayout.LayoutParams backgroundParams =
        new AbsoluteLayout.LayoutParams(
            item.getGeometry().getWidth(), item.getGeometry().getHeight(),
            item.getGeometry().getLeft(), item.getGeometry().getTop());
    backgroundImage.setLayoutParams(backgroundParams);

    AlphaAnimation animation = new AlphaAnimation(0f, 1.0f);
    animation.setDuration(item.getDuration() * 1000);
    animation.setRepeatCount(Animation.INFINITE);
    animation.setRepeatMode(Animation.REVERSE);
    backgroundImage.startAnimation(animation);
    layout.addView(backgroundImage);
  }
Пример #22
0
  public String SerializeGameData(int ACTIVITY_ID, String TAG) {
    String path = "";
    File direct = new File(Environment.getExternalStorageDirectory() + "/ShuffledWords");

    if (!direct.exists()) {
      if (direct.mkdir()) {
        // directory is created;
      }
    }

    ResumePackage rp = new ResumePackage();

    rp.DECKS = Data.shuffledDecks;
    rp.NUM_OF_DECKS = Data.numOfdecks;
    rp.NUM_OF_CARDS = Data.numOfCards;
    rp.SET_OF_CARDS = Data.setOfCards;
    rp.NUM_OF_PLAYERS = Data.numOfPlayers;
    rp.OPENCARD = Data.OpenCard;
    rp.CLOSECARD = Data.CloseCard;
    rp.CURRENT_PLAYER = Data.currentPlayer;
    rp.ACTIVITY_ID = ACTIVITY_ID;

    rp.PLAYERS_NAME = Data.name;
    rp.PLAYERS_PASSWORD = Data.pass;
    rp.PLAYERS_IMAGE = Data.path;

    rp.C_TIME = Timer.currentTime;
    rp.T_TIME = Timer.cummulativeTime;
    rp.ROUNDS = Timer.rounds;
    rp.ID = Data.Player_ID;
    rp.WRONG_DECLARE_PLAYER = WrongDeclare.WrongDeclarePlayer;

    Log.v("ID[0]", String.valueOf(rp.ID[0]));
    Log.v("ID[1]", String.valueOf(rp.ID[1]));

    Log.v("NAME[0]", String.valueOf(rp.PLAYERS_NAME[0]));
    Log.v("NAME[1]", String.valueOf(rp.PLAYERS_NAME[1]));

    Log.v("PASSWORD[0]", String.valueOf(rp.PLAYERS_PASSWORD[0]));
    Log.v("PASSWORD[1]", String.valueOf(rp.PLAYERS_PASSWORD[1]));

    Log.v("PLAYERS_IMAGE[0]", String.valueOf(rp.PLAYERS_IMAGE[0]));
    Log.v("PLAYERS_IMAGE[1]", String.valueOf(rp.PLAYERS_IMAGE[1]));

    try {
      path = Environment.getExternalStorageDirectory() + "/" + "ShuffledWords" + "/" + TAG + ".txt";
      FileOutputStream fileOut = new FileOutputStream(path);
      ObjectOutputStream out = new ObjectOutputStream(fileOut);
      out.writeObject(rp);
      out.close();
      fileOut.close();
    } catch (IOException i) {
      i.printStackTrace();
    }

    return path;
  }
  private void button_Write_save() {
    Spinner spinner;
    Text text;

    // ディレクトリの作成
    String target_path =
        Environment.getExternalStorageDirectory().getAbsolutePath() + "/Yukari/Write/Pregnancy";
    File dir = new File(target_path);
    if (!dir.exists()) {
      dir.mkdirs();
    }
    DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance();
    try {
      DocumentBuilder dbuilder = dbfactory.newDocumentBuilder();
      Document document = dbuilder.newDocument();
      Element root = document.createElement("members");

      // edittextの中身を保存
      for (int i1 = 0; i1 < item_checkup_EditText_8.length; i1++) {
        Element element1 = document.createElement(item_checkup_EditText_8tag[i1]);
        String string1 =
            ((EditText) findViewById(item_checkup_EditText_8[i1])).getText().toString();
        text = document.createTextNode(string1);
        element1.appendChild(text);
        root.appendChild(element1);
      }

      document.appendChild(root);

      TransformerFactory tffactory = TransformerFactory.newInstance();
      Transformer transformer = tffactory.newTransformer();

      // 保存ファイルの作成
      String filePath = Environment.getExternalStorageDirectory() + filepath;
      File file = new File(filePath);
      file.getParentFile().mkdir();
      transformer.transform(new DOMSource(document), new StreamResult(file));

    } catch (ParserConfigurationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (TransformerConfigurationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (TransformerException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    Toast.makeText(this, "保存が完了しました", Toast.LENGTH_LONG).show();
    Intent intent_cancel = new Intent(getApplicationContext(), pregnancy_inspection_record.class);
    startActivity(intent_cancel);

    finish();
  }
Пример #24
0
  public static void getAvatarForUser(final User user) {
    File storagePath =
        new File(
            Environment.getExternalStorageDirectory(),
            "/Android/data/com.zision.styggdrasil/avatars");
    if (!storagePath.isDirectory()) storagePath.mkdirs();
    final File path = new File(storagePath, user.username);
    if (path.isFile()) {
      user.avatar = BitmapFactory.decodeFile(path.toString());
      return;
    } else {
      user.avatar =
          BitmapFactory.decodeFile(
              new File(
                      Environment.getExternalStorageDirectory(),
                      "/Android/data/com.zision.styggdrasil/defaultpic.png")
                  .toString());
      new Thread(
              new Runnable() {
                @Override
                public void run() {
                  URL url = user.avatarUrl;
                  InputStream input;
                  try {
                    input = url.openStream();
                  } catch (IOException e1) {
                    return;
                  }
                  try {
                    OutputStream output = new FileOutputStream(path);
                    try {
                      byte[] buffer = new byte[4096];
                      int bytesRead = 0;
                      while ((bytesRead = input.read(buffer, 0, buffer.length)) >= 0) {
                        output.write(buffer, 0, bytesRead);
                      }
                    } finally {
                      output.close();
                    }
                  } catch (IOException e) {
                  } finally {

                    try {
                      input.close();
                    } catch (IOException e) {
                      return;
                    }
                    user.avatar = BitmapFactory.decodeFile(path.toString());
                  }
                }
              })
          .start();
    }
  }
Пример #25
0
  public int dbFileOperation(String... params) {
    // 默认路径是 /data/data/(包名)/databases/*.db
    File dbFile = null;
    File backupDir = null;
    String command1 = params[1];
    if (command1.equals(COMMAND_ISCONTACT)) {
      dbFile = mContext.getDatabasePath("/data/data/cn.sqy.contacts/databases/contact.db");
      backupDir = new File(Environment.getExternalStorageDirectory(), "contactsBackup");
    } else if (command1.equals(COMMAND_ISMESSAGE)) {
      dbFile = mContext.getDatabasePath("/data/data/cn.sqy.contacts/databases/msg.db");
      backupDir = new File(Environment.getExternalStorageDirectory(), "msgBackup");
    } else {
      return -1;
    }

    if (!backupDir.exists()) {
      backupDir.mkdirs();
    }
    File backup = new File(backupDir, dbFile.getName());
    String command2 = params[0];
    if (command2.equals(COMMAND_BACKUP)) {
      try {
        if (command1.equals(COMMAND_ISCONTACT)) {
          backup.createNewFile();
          fileCopy(dbFile, backup);
          return 0;
        } else {
          msgMgr.insertMsgsFromSysAllMsgs(); // 再将系统短信导入到数据库
          backup.createNewFile(); // 最后再把数据库备份到SD卡上
          fileCopy(dbFile, backup);
          return 3;
        }
      } catch (Exception e) {
        e.printStackTrace();
        return -1;
      }
    } else if (command2.equals(COMMAND_RESTORE)) {
      try {
        if (command1.equals(COMMAND_ISCONTACT)) {
          fileCopy(backup, dbFile);
          return 1;
        } else {
          fileCopy(backup, dbFile); // 先把数据库从SD卡上恢复到我的数据库
          msgMgr.insertIntoSysMsgFromMyMsg(); // 再从我的数据库导入到系统数据库中
          return 4;
        }
      } catch (Exception e) {
        e.printStackTrace();
        return -1;
      }
    } else {
      return -1;
    }
  }
Пример #26
0
 /**
  * 获取存储路径
  *
  * @return
  */
 public static String getExternalStoragePath() {
   // 获取SdCard状态
   String state = android.os.Environment.getExternalStorageState();
   // 判断SdCard是否存在并且是可用的
   if (android.os.Environment.MEDIA_MOUNTED.equals(state)) {
     if (android.os.Environment.getExternalStorageDirectory().canWrite()) {
       return android.os.Environment.getExternalStorageDirectory().getPath();
     }
   }
   return null;
 }
Пример #27
0
 private void discardStory() {
   Util.deleteFile(
       new File(
           Environment.getExternalStorageDirectory(),
           ForTour.DIR_WORK + "/" + ForTour.DIR_THUMB + "/" + mFileName));
   Util.deleteFile(
       new File(Environment.getExternalStorageDirectory(), ForTour.DIR_WORK + "/" + mFileName));
   Util.deleteFile(
       new File(
           Environment.getExternalStorageDirectory(), ForTour.DIR_WORK + "/" + mMediaFileName));
 }
Пример #28
0
  public void testLastWornOutfit() {
    File calendar =
        new File(
            Environment.getExternalStorageDirectory() + "/OutfitSifter/" + UserName + "/Calendar/");
    ArrayList<File> calOutfits = new ArrayList<File>();
    if (calendar.exists()) {
      for (File f : calendar.listFiles()) {
        calOutfits.add(f);
      }
      String top = topData.get(itemCount);
      String bottom = bottomData.get(itemCount);
      String shoe = shoeData.get(itemCount);

      if (calOutfits.size() > 0) {
        int verifyOutfit = 0;
        String date = "";
        for (int i = 0; i < calOutfits.size(); i++) {
          try {
            if (calOutfits.get(i).getName().indexOf(".txt") != -1) {
              File outfit =
                  new File(
                      Environment.getExternalStorageDirectory()
                          + "/OutfitSifter/"
                          + UserName
                          + "/Calendar/"
                          + calOutfits.get(i).getName());
              Scanner in = new Scanner(outfit);
              while (in.hasNextLine()) {
                String line = in.nextLine();
                if (line.equals(top)) {
                  line = in.nextLine();
                  if (line.equals(bottom)) {
                    line = in.nextLine();
                    if (line.equals(shoe)) {
                      verifyOutfit++;
                      date = calOutfits.get(i).getName();
                      date = date.substring(0, date.length() - 4);
                    }
                  }
                }
              }
              in.close();
            }
          } catch (Exception e) {
          }
        }

        if (verifyOutfit > 0) {
          Toast.makeText(context, "Last worn " + date, Toast.LENGTH_SHORT).show();
        }
      }
    }
  }
Пример #29
0
 public static interface Paths {
   public static final File PATH_BACKUP =
       new File(Environment.getExternalStorageDirectory(), ".%realProjectName%/backup");
   public static final File PATH_BINARIES =
       new File(Environment.getExternalStorageDirectory(), ".%realProjectName%/binaries");
   public static final File PATH_SYNCHRO =
       new File(Environment.getExternalStorageDirectory(), ".%realProjectName%/synchro");
   public static final File PATH_TEMPORARY =
       new File(Environment.getExternalStorageDirectory(), ".%realProjectName%/temporary");
   public static final File PATH_MEDIA =
       new File(Environment.getExternalStorageDirectory(), "%realProjectName%/media");
 }
 public void rsaCypher(String rString, InputStream inputStream, File directory)
     throws InvalidKeyException, NoSuchPaddingException, NoSuchAlgorithmException, IOException,
         BadPaddingException, IllegalBlockSizeException {
   kpg = KeyPairGenerator.getInstance("RSA");
   kpg.initialize(1024);
   kp = kpg.genKeyPair();
   privateKey = kp.getPrivate();
   cipher = Cipher.getInstance("RSA");
   File root = new File(Environment.getExternalStorageDirectory() + "/Notes/", "rsapublick.txt");
   // Read text from file
   if (root.exists()) {
     StringBuilder text = new StringBuilder();
     try {
       BufferedReader br = new BufferedReader(new FileReader(root));
       String line;
       while ((line = br.readLine()) != null) {
         text.append(line);
         text.append('\n');
       }
       br.close();
       byte[] keyBytes = Base64.decode(text.toString().getBytes("utf-8"), 0);
       X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes);
       KeyFactory keyFactory = KeyFactory.getInstance("RSA");
       publicKey = keyFactory.generatePublic(spec);
     } catch (IOException e) {
       // You'll need to add proper error handling here
     } catch (InvalidKeySpecException e) {
       e.printStackTrace();
     }
   } else {
     publicKey = kp.getPublic();
     byte[] pKbytes = Base64.encode(publicKey.getEncoded(), 0);
     String pK = new String(pKbytes);
     String pubKey = "-----BEGIN public KEY-----\n" + pK + "-----END public KEY-----\n";
     System.out.println(pubKey);
     generateNoteOnSD("rsapublick.txt", pK, directorio);
   }
   this.cipher.init(Cipher.ENCRYPT_MODE, publicKey);
   byte[] bytes = getBytesFromInputStream(inputStream);
   byte[] encrypted = blockCipher(bytes, Cipher.ENCRYPT_MODE);
   FileOutputStream fileOutputStream = new FileOutputStream(directory);
   fileOutputStream.write(encrypted);
   fileOutputStream.close();
   System.out.println("Encryptado RSA Finalizado");
   root = new File(Environment.getExternalStorageDirectory() + "/Notes/", "rsaOrivatek.txt");
   if (!root.exists()) {
     byte[] pKbytes = Base64.encode(getPrivateKey().getEncoded(), 0);
     String pK = new String(pKbytes);
     String pubKey = "-----BEGIN private KEY-----\n" + pK + "-----END private KEY-----\n";
     System.out.println(pubKey);
     generateNoteOnSD("rsaOrivatek.txt", pK, directorio);
   }
 }