private boolean copyAssetsToFilesystem(String assetsSrc, String des) {
   if (SQLiteDebug.isDebug) {
     Log.i(TAG, "Copy " + assetsSrc + " to " + des);
   }
   InputStream istream = null;
   OutputStream ostream = null;
   try {
     AssetManager am = context.getAssets();
     istream = am.open(assetsSrc);
     ostream = new FileOutputStream(des);
     byte[] buffer = new byte[1024 * 64];
     int length;
     while ((length = istream.read(buffer)) > 0) {
       ostream.write(buffer, 0, length);
     }
     istream.close();
     ostream.close();
   } catch (Exception e) {
     e.printStackTrace();
     try {
       if (istream != null) istream.close();
       if (ostream != null) ostream.close();
     } catch (Exception ee) {
       ee.printStackTrace();
     }
     return false;
   }
   return true;
 }
  protected boolean onTap(int index) {
    // System.out.println("item onTap: "+index);

    Bitmap[] bmps = new Bitmap[3];
    if (index % 2 == 0) {
      try {
        bmps[0] = BitmapFactory.decodeStream(mContext.getAssets().open("marker1.png"));
        bmps[1] = BitmapFactory.decodeStream(mContext.getAssets().open("marker2.png"));
        bmps[2] = BitmapFactory.decodeStream(mContext.getAssets().open("marker3.png"));
      } catch (IOException e) {
        e.printStackTrace();
      }
    } else {
      try {
        bmps[2] = BitmapFactory.decodeStream(mContext.getAssets().open("marker1.png"));
        bmps[1] = BitmapFactory.decodeStream(mContext.getAssets().open("marker2.png"));
        bmps[0] = BitmapFactory.decodeStream(mContext.getAssets().open("marker3.png"));
      } catch (IOException e) {
        e.printStackTrace();
      }
    }

    // pop.showPopup(bmps, getItem(index).getPoint(), 32);
    // if (null == mToast)
    //  mToast = Toast.makeText(mContext, getItem(index).getTitle(), Toast.LENGTH_SHORT);
    // else mToast.setText(getItem(index).getTitle());
    // mToast.show();

    if (mH != null) {
      mH.dispatchMessage(mH.obtainMessage(LocationOverlayDemo.MSG_HANDLE_ITEM_TOUCH + index));
    }

    return true;
  }
 public FiveStepsTableArrayAdapter(Context var1, int var2, List var3) {
   super(var1, var2, var3);
   this.light = Typeface.createFromAsset(var1.getAssets(), "nexa_light.otf");
   this.bold = Typeface.createFromAsset(var1.getAssets(), "nexa_bold.otf");
   this.context = var1;
   this.mIdMap = var3;
 }
Example #4
0
  public static void copyAssetsFromPackage(Context ctx, String fromPath) throws IOException {
    new File(ctx.getFilesDir().getPath() + "/" + fromPath).mkdir();

    for (String f : ctx.getAssets().list(fromPath)) {
      String current_name = fromPath + "/" + f;
      InputStream lInputStream;
      try {
        lInputStream = ctx.getAssets().open(current_name);
      } catch (IOException e) {
        // probably a dir
        new File(ctx.getFilesDir().getPath() + "/" + current_name).mkdir();
        copyAssetsFromPackage(ctx, current_name);
        continue;
      }
      FileOutputStream lOutputStream =
          new FileOutputStream(
              new File(
                  ctx.getFilesDir().getPath()
                      + "/"
                      + current_name)); // ctx.openFileOutput (fromPath+"/"+f, 0);

      int readByte;
      byte[] buff = new byte[8048];
      while ((readByte = lInputStream.read(buff)) != -1) {
        lOutputStream.write(buff, 0, readByte);
      }
      lOutputStream.flush();
      lOutputStream.close();
      lInputStream.close();
    }
  }
Example #5
0
 /** Copies assets to /data/data/com.binoy.vibhinna/bin and sets permissions */
 public void copyAssets() {
   // FIXME use package name.
   Toast.makeText(context, R.string.copying_binaries, Toast.LENGTH_SHORT).show();
   String[] assetslist = null;
   try {
     assetslist = context.getAssets().list(ASSETS_FOLDER);
   } catch (IOException e) {
     Toast.makeText(context, R.string.error_copying_binaries, Toast.LENGTH_SHORT).show();
   }
   for (int i = 0; i < assetslist.length; i++) {
     try {
       InputStream in = context.getAssets().open(ASSETS_FOLDER + Constants.SLASH + assetslist[i]);
       FileOutputStream out =
           new FileOutputStream(Constants.BINARY_PATH + Constants.SLASH + assetslist[i]);
       int read;
       byte[] buffer = new byte[4096];
       while ((read = in.read(buffer)) > 0) {
         out.write(buffer, 0, read);
       }
       out.close();
       in.close();
       File assetfile = new File(Constants.BINARY_PATH + Constants.SLASH + assetslist[i]);
       assetfile.setReadable(true, false);
       assetfile.setExecutable(true, false);
     } catch (FileNotFoundException e) {
       e.printStackTrace();
       Log.w(TAG, "Error : File not found " + assetslist[i]);
     } catch (IOException e) {
       e.printStackTrace();
       Log.w(TAG, "IO Error " + assetslist[i]);
     }
   }
 }
Example #6
0
  /**
   * Set the special phrases to a certain language. This method needs to be used before the
   * getSpecialPhrase method
   *
   * @param lang the language to use
   * @throws IOException when reading the text file failed
   */
  public static void setLanguage(Context ctx, OsmandSettings settings) throws IOException {
    String lang = getPreferredLanguage(settings).getLanguage();
    m = new HashMap<String, String>();
    // The InputStream opens the resourceId and sends it to the buffer
    InputStream is = null;
    BufferedReader br = null;
    try {
      try {
        is = ctx.getAssets().open("specialphrases/specialphrases_" + lang + ".txt");
      } catch (IOException ex) {
        // second try: default to English, if this fails, the error is thrown outside
        is = ctx.getAssets().open("specialphrases/specialphrases_en.txt");
      }
      br = new BufferedReader(new InputStreamReader(is));
      String readLine = null;

      // While the BufferedReader readLine is not null
      while ((readLine = br.readLine()) != null) {
        String[] arr = readLine.split(",");
        if (arr != null && arr.length == 2) {
          m.put(arr[0], arr[1]);
        }
      }

    } finally {
      Algoritms.closeStream(is);
      Algoritms.closeStream(br);
    }
  }
 public FlipAdapter(Context paramContext, List<Item> items) {
   this.items = items;
   this.context = paramContext;
   futuraTypeface = Typeface.createFromAsset(paramContext.getAssets(), "font/futura.ttf");
   muktiTypeface = Typeface.createFromAsset(paramContext.getAssets(), "font/mukti.ttf");
   this.inflater = LayoutInflater.from(paramContext);
 }
 private void initialize(View fragmentView, Context context) {
   ButterKnife.bind(this, fragmentView);
   Typeface robotoBlack = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Black.ttf");
   txtGuideLine.setTypeface(robotoBlack);
   Typeface robotoCondensedLight =
       Typeface.createFromAsset(context.getAssets(), "fonts/RobotoCondensed-Light.ttf");
   edtNidName.setTypeface(robotoCondensedLight);
   edtNidBirthDate.setTypeface(robotoCondensedLight);
   edtNidNo.setTypeface(robotoCondensedLight);
   fab.setOnClickListener(fabOnClickListener);
   edtNidBirthDate.setOnClickListener(
       new View.OnClickListener() {
         @Override
         public void onClick(View v) {
           showDialog();
         }
       });
   imgDatePicker.setOnClickListener(
       new View.OnClickListener() {
         @Override
         public void onClick(View v) {
           showDialog();
         }
       });
 }
  @Override
  public void bindView(View view, Context context, Cursor cursor) {
    // here we are setting our data
    // that means, take the data from the cursor and put it in views
    TextView code = (TextView) view.findViewById(R.id.txtCodel);
    TextView title = (TextView) view.findViewById(R.id.txtTitle);
    TextView lessontime = (TextView) view.findViewById(R.id.txtTimes);
    TextView teacher = (TextView) view.findViewById(R.id.txtTeacher);
    TextView location = (TextView) view.findViewById(R.id.txtLocation);
    TextView txtPm = (TextView) view.findViewById(R.id.textView1);
    TextView color = (TextView) view.findViewById(R.id.txtcolor);

    code.setText(cursor.getString(cursor.getColumnIndex(cursor.getColumnName(3))));
    title.setText(cursor.getString(cursor.getColumnIndex(cursor.getColumnName(4))));
    teacher.setText(cursor.getString(cursor.getColumnIndex(cursor.getColumnName(8))));
    location.setText(cursor.getString(cursor.getColumnIndex(cursor.getColumnName(9))));
    color.setText(cursor.getString(cursor.getColumnIndex(cursor.getColumnName(7))));

    Typeface font = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Light.ttf");
    Typeface font_a = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Medium.ttf");
    Typeface font_b = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Regular.ttf");
    Typeface font_c = Typeface.createFromAsset(context.getAssets(), "fonts/DistProTh.otf");
    Typeface font_d = Typeface.createFromAsset(context.getAssets(), "fonts/DroidSans.ttf");
    code.setTypeface(font_b);
    lessontime.setTypeface(font_c);
    title.setTypeface(font_a);
    teacher.setTypeface(font_b);
    location.setTypeface(font_b);
    txtPm.setTypeface(font_b);

    String startTime = cursor.getString(cursor.getColumnIndex(cursor.getColumnName(5)));
    String endTime = cursor.getString(cursor.getColumnIndex(cursor.getColumnName(6)));
    String pn = "am";
    double a = Float.parseFloat(startTime) / 100;
    double c = Float.parseFloat(endTime) / 100;

    if (a > 12) {
      // pn="am";
      txtPm.setText(pn);
      a = a - 12;
      if (a < 1) a = a + 1;
    }

    if (c > 12) {
      pn = "pm";
      txtPm.setText(pn);
      c = c - 12;
      if (c < 0.59) c = c + 1;
    } else {
      pn = "am";
      txtPm.setText(pn);
    }
    String m = df.format(a) + "-" + df.format(c);
    m = m.replaceAll("[.]", ":");
    lessontime.setText(m);
  }
Example #10
0
  public SettingsDialog(Context context) {
    super(context, R.style.FullscreenDialogTheme);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.settings_dialog);

    settings = context.getSharedPreferences("NotifyMeSettings", context.MODE_PRIVATE);
    prefEditor = settings.edit();

    Typeface font = Typeface.createFromAsset(context.getAssets(), "fonts/VarelaRound-Regular.ttf");
    Typeface font2 =
        Typeface.createFromAsset(context.getAssets(), "fonts/DINEngschrift-Regular.ttf");

    dialogText = (TextView) findViewById(R.id.settings_header);
    dialogText.setTypeface(font);

    deleteAllButton = (Button) findViewById(R.id.delete_all);
    deleteAllButton.setTypeface(font2);

    saveButton = (Button) findViewById(R.id.save_button);
    saveButton.setTypeface(font2);

    toneBox = (CheckBox) findViewById(R.id.toneCheckBox);
    vibrateBox = (CheckBox) findViewById(R.id.vibrateCheckBox);
    toneBox.setTypeface(font);
    vibrateBox.setTypeface(font);

    if (settings.contains("tone") == false) {
      toneBox.setChecked(true);
    } else {
      if (settings.getBoolean("tone", true)) {
        toneBox.setChecked(true);
      } else {
        toneBox.setChecked(false);
      }
    }

    if (settings.contains("vibration") == false) {
      vibrateBox.setChecked(true);
    } else {
      if (settings.getBoolean("vibration", true)) {
        vibrateBox.setChecked(true);
      } else {
        vibrateBox.setChecked(false);
      }
    }

    saveButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            prefEditor.putBoolean("tone", toneBox.isChecked());
            prefEditor.putBoolean("vibration", vibrateBox.isChecked());
            prefEditor.commit();
            cancel();
          }
        });
  }
Example #11
0
 public Typeface getTypefaceTextView(Context context, String font) {
   if (font.equals("bold")) {
     if (typefaceHelveticaBold == null)
       typefaceHelveticaBold =
           Typeface.createFromAsset(context.getAssets(), "fonts/HelveticaWorldBold.ttf");
     return typefaceHelveticaBold;
   } else {
     if (typefaceHelveticaRegular == null)
       typefaceHelveticaRegular =
           Typeface.createFromAsset(context.getAssets(), "fonts/HelveticaWorldRegular.ttf");
     return typefaceHelveticaRegular;
   }
 }
Example #12
0
 private LocalWays(Context ctx) {
   try {
     ways =
         JsonElement.readFrom(new InputStreamReader(ctx.getAssets().open("tracks.json")))
             .asJsonArray();
     pois =
         JsonElement.readFrom(new InputStreamReader(ctx.getAssets().open("points.json")))
             .asJsonArray();
   } catch (IOException e) {
     e.printStackTrace();
     new RuntimeException("We cannot read ways!!!");
   }
 }
Example #13
0
  private void loadCustomeFonts(Context context) {

    // load fonts in fixed order, 0=normal, 1=bold, 2=italic, 3=bolditalic
    String[] fontList = context.getResources().getStringArray(R.array.fonts);
    fonts = new Typeface[fontList.length];
    qabelFont =
        Typeface.createFromAsset(
            context.getAssets(), context.getResources().getString(R.string.asset_qabel_font));

    for (int i = 0; i < fontList.length; i++) {
      fonts[i] = Typeface.createFromAsset(context.getAssets(), fontList[i]);
    }
  }
  public SelectSubwayDialog(Context context) {
    super(context, R.style.FullscreenDialogTheme);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.train_select_dialog);

    Typeface font = Typeface.createFromAsset(context.getAssets(), "fonts/VarelaRound-Regular.ttf");
    Typeface font2 =
        Typeface.createFromAsset(context.getAssets(), "fonts/DINEngschrift-Regular.ttf");

    saveButton = (Button) findViewById(R.id.save_button);
    saveButton.setTypeface(font2);

    cancelButton = (Button) findViewById(R.id.cancel_button);
    cancelButton.setTypeface(font2);

    dialogText = (TextView) findViewById(R.id.other_lines_text);
    dialogText.setTypeface(font);
    subwayLinesHolder = (LinearLayout) findViewById(R.id.subway_lines_holder);

    cancelButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            cancel();
          }
        });

    Resources res = context.getResources();
    String[] trainLines = res.getStringArray(R.array.trains_array);

    for (int i = 0; i < trainLines.length; i++) {
      final SelectSubwayButton tlb = (SelectSubwayButton) findViewById(lineIdArray[i]);
      lineButtonArray.add(tlb);
      tlb.setImages(lineImageArray[i], lineImageSelectedArray[i], trainLines[i]);
      tlb.setOnClickListener(
          new View.OnClickListener() {

            public void onClick(View v) {
              SelectSubwayButton tb = (SelectSubwayButton) v;
              if (tb.selected) {
                tb.setDeSelected();
                checkedLinesArray.remove(tb.id);
              } else {
                tb.setSelected();
                checkedLinesArray.add(tb.id);
              }
            }
          });
    }
  }
Example #15
0
  /**
   * č®¾å®šéŸ³ä¹ę’­ę”¾ęŗļ¼Œå¹¶č®¾ē½®ę˜Æ否å¾ŖēŽÆę’­ę”¾
   *
   * @param file
   * @param looping
   */
  public void setDataSource(String file, boolean looping) {
    synchronized (this.lock) {
      try {
        player.setDataSource(
            context.getAssets().openFd(file).getFileDescriptor(),
            context.getAssets().openFd(file).getStartOffset(),
            context.getAssets().openFd(file).getLength());
        player.prepare();
        player.setLooping(looping);
      } catch (Exception e) {

      }
      lock.notifyAll();
    }
  }
  public void loadSound(Context context) {
    soundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
    try {
      AssetManager assetManager = context.getAssets();
      AssetFileDescriptor descriptor;

      // Second parameter specifies priority of sound effect
      descriptor = assetManager.openFd("match_found.ogg");
      matchFoundID = soundPool.load(descriptor, 0);

      descriptor = assetManager.openFd("swap_back.ogg");
      invalidMoveID = soundPool.load(descriptor, 0);

      descriptor = assetManager.openFd("angry.ogg");
      angryID = soundPool.load(descriptor, 0);

      descriptor = assetManager.openFd("delighted.ogg");
      delightedID = soundPool.load(descriptor, 0);

      descriptor = assetManager.openFd("embarrassed.ogg");
      embarrassedID = soundPool.load(descriptor, 0);

      descriptor = assetManager.openFd("surprised.ogg");
      surprisedID = soundPool.load(descriptor, 0);

      descriptor = assetManager.openFd("upset.ogg");
      upsetID = soundPool.load(descriptor, 0);

    } catch (IOException e) {
      Log.e("Error", "sound file failed to load!");
    }
  }
  public String getDeviceName(Context context) {
    String manufacturer = Build.MANUFACTURER;
    String undecodedModel = Build.MODEL;
    String model = null;

    try {
      Properties prop = new Properties();
      InputStream fileStream;
      // Read the device name from a precomplied list:
      // see http://making.meetup.com/post/29648976176/human-readble-android-device-names
      fileStream = context.getAssets().open("android_models.properties");
      prop.load(fileStream);
      fileStream.close();
      String decodedModel = prop.getProperty(undecodedModel.replaceAll(" ", "_"));
      if (decodedModel != null && !decodedModel.trim().equals("")) {
        model = decodedModel;
      }
    } catch (IOException e) {
      AppLog.e(T.UTILS, e.getMessage());
    }

    if (model == null) { // Device model not found in the list
      if (undecodedModel.startsWith(manufacturer)) {
        model = capitalize(undecodedModel);
      } else {
        model = capitalize(manufacturer) + " " + undecodedModel;
      }
    }
    return model;
  }
Example #18
0
  public Drawable getDrawable(String url) {
    try {
      String filename = url.substring(url.lastIndexOf("/") + 1);
      filename = filename.substring(0, filename.lastIndexOf("."));
      Drawable d;

      if (Arrays.binarySearch(emotionArray, filename) >= 0) {
        Log.d(TAG, "Emotion hit!");
        d = Drawable.createFromStream(context.getAssets().open(filename + ".gif"), filename);
      } else {
        File cacheDir = Utils.ensureCache(context, "image_cache");
        File f = new File(cacheDir, filename + ".png");
        if (!f.exists()) {
          downloadImage(url, f);
        }
        d = Drawable.createFromPath(f.getAbsolutePath());
      }
      setBound(d);
      return d;
    } catch (Exception e) {
      Log.d(TAG, "Download: " + url + " error!", e);
    }

    return null;
  }
Example #19
0
 public static SQLiteDatabase OpenDataBase(Context mContext, String dbName, String assertDBName) {
   File dataFolder = mContext.getFilesDir();
   File dbFile = new File(dataFolder.getAbsolutePath() + "/" + dbName);
   Log.v("DataCenter", dbFile.getAbsolutePath());
   if (!dbFile.exists()) {
     try {
       InputStream inputStream = mContext.getAssets().open(assertDBName);
       FileOutputStream fso = new FileOutputStream(dbFile);
       byte[] buffer = new byte[1024];
       int readCount = 0;
       while ((readCount = inputStream.read(buffer)) > 0) {
         fso.write(buffer);
       }
       inputStream.close();
       fso.close();
     } catch (IOException e) {
       // TODO: handle exception
       e.printStackTrace();
     }
   }
   SQLiteDatabase db =
       SQLiteDatabase.openDatabase(
           dbFile.getAbsolutePath(), null, SQLiteDatabase.CREATE_IF_NECESSARY);
   return db;
 }
    private void setFont() {

      Typeface custom_font = Typeface.createFromAsset(mContext.getAssets(), "Calibri.ttf");

      mesage.setTypeface(custom_font);
      comment.setTypeface(custom_font);
    }
Example #21
0
  public static @NonNull LinkedList<ThemeInfo> enumerateThemes(@NonNull Context context) {
    LinkedList<ThemeInfo> themes = new LinkedList<>();
    AssetManager manager = context.getAssets();

    // load themes from assets
    try {
      String[] builtin_themes = manager.list("");
      for (String theme : builtin_themes) {
        if (!theme.toLowerCase().endsWith("theme.properties")) continue;
        Properties p = loadColorScheme(theme, manager);
        if (p != null) themes.add(new ThemeInfo(p.getProperty("NAME", theme), theme));
      }
    } catch (IOException e) {
      e.printStackTrace();
    }

    // load themes from disk
    File dir = new File(SEARCH_DIR);
    if (dir.exists()) {
      File[] files = dir.listFiles();
      if (files != null) {
        for (File file : files) {
          if (!file.getName().toLowerCase().endsWith("theme.properties")) continue;
          Properties p = loadColorScheme(file.getAbsolutePath(), null);
          if (p != null)
            themes.add(
                new ThemeInfo(p.getProperty("NAME", file.getName()), file.getAbsolutePath()));
        }
      }
    }
    return themes;
  }
Example #22
0
  /**
   * Copies your database from your local assets-folder to the just created empty database in the
   * system folder, from where it can be accessed and handled. This is done by transfering
   * bytestream.
   */
  private void copyDataBase() throws IOException {

    try {
      InputStream myInput = myContext.getAssets().open(DB_NAME);
      // Path to the just created empty db
      String outFileName = DB_PATH + DB_NAME;
      // Open the empty db as the output stream

      final File dir = new File(DB_PATH);
      if (dir.exists() == false) {
        dir.mkdirs(); // create folders where write files
      }

      OutputStream myOutput = new FileOutputStream(outFileName);
      // transfer bytes from the inputfile to the outputfile
      byte[] buffer = new byte[1024];
      int length;
      while ((length = myInput.read(buffer)) > 0) {

        myOutput.write(buffer, 0, length);
      }

      // Close the streams
      myOutput.flush();
      myOutput.close();
      myInput.close();

    } catch (IOException e) {

      throw new Error("Database kopyalarken hata oluĆ¾tu : " + e.getMessage());
    }
    // Open your local db as the input stream

  }
  public static void get_assetsScript(String fn, Context c, String prefix, String postfix) {
    byte[] buffer;
    final AssetManager assetManager = c.getAssets();
    try {
      InputStream f = assetManager.open(fn);
      buffer = new byte[f.available()];
      f.read(buffer);
      f.close();
      final String s = new String(buffer);
      final StringBuffer sb = new StringBuffer(s);
      if (!postfix.equals("")) {
        sb.append("\n\n" + postfix);
      }
      if (!prefix.equals("")) {
        sb.insert(0, prefix + "\n");
      }
      sb.insert(0, "#!" + Helpers.binExist("sh") + "\n\n");
      try {
        FileOutputStream fos;
        fos = c.openFileOutput(fn, Context.MODE_PRIVATE);
        fos.write(sb.toString().getBytes());
        fos.close();

      } catch (IOException e) {
        Log.d(TAG, "error write " + fn + " file");
        e.printStackTrace();
      }

    } catch (IOException e) {
      Log.d(TAG, "error read " + fn + " file");
      e.printStackTrace();
    }
  }
Example #24
0
 public MyCustomView(Context context, AttributeSet attrs) {
   super(context, attrs);
   Typeface typeface = Typeface.createFromAsset(context.getAssets(), "ARLRDBD.TTF");
   setTypeface(typeface);
   setTextColor(android.graphics.Color.WHITE);
   setTextSize(18);
 }
 /**
  * Creates and returns Roboto typeface and caches it.
  *
  * @param context {@link android.content.Context} Context that will obtain resources.
  * @param fontType {@link com.tripadvisor.seekbar.util.Utils.FontType} LIGHT, MEDIUM, REGULAR, or
  *     BOLD
  * @return Returns the {@link android.graphics.Typeface} corresponding to the {@link
  *     com.tripadvisor.seekbar.util.Utils.FontType}
  */
 public static Typeface getRobotoTypeface(Context context, FontType fontType) {
   String fontPath = sFontMap.get(fontType);
   if (!sTypefaceCache.containsKey(fontType)) {
     sTypefaceCache.put(fontType, Typeface.createFromAsset(context.getAssets(), fontPath));
   }
   return sTypefaceCache.get(fontType);
 }
  private LocalRepoManager(Context c) {
    context = c.getApplicationContext();
    pm = c.getPackageManager();
    assetManager = c.getAssets();
    fdroidPackageName = c.getPackageName();

    webRoot = SanitizedFile.knownSanitized(c.getFilesDir());
    /* /fdroid/repo is the standard path for user repos */
    fdroidDir = new SanitizedFile(webRoot, "fdroid");
    fdroidDirCaps = new SanitizedFile(webRoot, "FDROID");
    repoDir = new SanitizedFile(fdroidDir, "repo");
    repoDirCaps = new SanitizedFile(fdroidDirCaps, "REPO");
    iconsDir = new SanitizedFile(repoDir, "icons");
    xmlIndex = new SanitizedFile(repoDir, "index.xml");
    xmlIndexJar = new SanitizedFile(repoDir, "index.jar");
    xmlIndexJarUnsigned = new SanitizedFile(repoDir, "index.unsigned.jar");

    if (!fdroidDir.exists())
      if (!fdroidDir.mkdir()) Log.e(TAG, "Unable to create empty base: " + fdroidDir);

    if (!repoDir.exists())
      if (!repoDir.mkdir()) Log.e(TAG, "Unable to create empty repo: " + repoDir);

    if (!iconsDir.exists())
      if (!iconsDir.mkdir()) Log.e(TAG, "Unable to create icons folder: " + iconsDir);
  }
 static boolean applyFontToTextView(
     final Context context, final TextView textView, final String filePath, boolean deferred) {
   if (textView == null || context == null) return false;
   final AssetManager assetManager = context.getAssets();
   final Typeface typeface = TypefaceUtils.load(assetManager, filePath);
   return applyFontToTextView(textView, typeface, deferred);
 }
  private void copyDataBase() throws IOException {
    /**
     * Copies your database from your local assets-folder to the just created empty database in the
     * system folder, from where it can be accessed and handled. This is done by transferring byte
     * stream.
     */

    // Open your local db as the input stream
    InputStream myInput = context.getAssets().open(DATABASE_NAME);

    // Path to the just created empty db
    String outFileName = DB_PATH + DATABASE_NAME;

    // Open the empty db as the output stream
    OutputStream myOutput = new FileOutputStream(outFileName);

    // transfer bytes from the input file to the output file
    byte[] buffer = new byte[1024];
    int length;
    while ((length = myInput.read(buffer)) > 0) {
      myOutput.write(buffer, 0, length);
    }

    // Close the streams
    myOutput.flush();
    myOutput.close();
    myInput.close();
  }
Example #29
0
  /**
   * Copies your database from your local assets-folder to the just created empty database in the
   * system folder, from where it can be accessed and handled. This is done by transfering
   * bytestream.
   */
  private void copyDataBase() throws IOException {
    Log.d(TAG, "copyDataBase() called with: " + "");
    // Open your local db as the input stream
    ZipInputStream zipInputStream =
        new ZipInputStream(context.getAssets().open("data/" + DATABASE_NAME + ".zip"));
    ZipEntry entry;
    do {
      entry = zipInputStream.getNextEntry();
    } while (!entry.getName().equals(DATABASE_NAME));

    // InputStream myInput = context.getAssets().open(DATABASE_NAME);
    // Path to the just created empty db
    String outFileName = DATABASE_PATH + DATABASE_NAME;
    // Open the empty db as the output stream
    OutputStream myOutput = new FileOutputStream(outFileName);
    // transfer bytes from the inputfile to the outputfile
    byte[] buffer = new byte[1024];
    int length;
    while ((length = zipInputStream.read(buffer)) > 0) {
      myOutput.write(buffer, 0, length);
    }
    // Close the streams
    myOutput.flush();
    myOutput.close();
    zipInputStream.close();
  }
Example #30
0
 public InputStream openUpgradeScript(String gScriptName) {
   try {
     return context.getAssets().open(gScriptName);
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
 }