android.app.Activity.getAssets()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(335)

本文整理了Java中android.app.Activity.getAssets()方法的一些代码示例,展示了Activity.getAssets()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Activity.getAssets()方法的具体详情如下:
包路径:android.app.Activity
类名称:Activity
方法名:getAssets

Activity.getAssets介绍

暂无

代码示例

代码示例来源:origin: gzu-liyujiang/AndroidPicker

@Override
protected ArrayList<Province> doInBackground(Void... params) {
  Activity activity = activityReference.get();
  if (activity == null) {
    return null;
  }
  try {
    String data = ConvertUtils.toString(activity.getAssets().open("city.txt"));
    return parseData(data);
  } catch (java.io.IOException e) {
    e.printStackTrace();
    return null;
  }
}

代码示例来源:origin: gzu-liyujiang/AndroidPicker

Activity activity = activityReference.get();
if (activity != null) {
  String json = ConvertUtils.toString(activity.getAssets().open("city.json"));
  data.addAll(JSON.parseArray(json, Province.class));

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public void onAttach(Activity host) {
 super.onAttach(host);
 if (contents.get()==null) {
  new LoadThread(host.getAssets()).start();
 }
}

代码示例来源:origin: mayubao/KuaiChuan

String classifyHtml = IOStreamUtils.inputStreamToString(sActivity.getAssets().open(Constant.NAME_CLASSIFY_TEMPLATE));

代码示例来源:origin: schwabe/ics-openvpn

private void startEmbeddedProfile(boolean addNew)
{
  try {
    InputStream conf = getActivity().getAssets().open("test.conf");
    InputStreamReader isr = new InputStreamReader(conf);
    BufferedReader br = new BufferedReader(isr);
    String config="";
    String line;
    while(true) {
      line = br.readLine();
      if(line == null)
        break;
      config += line + "\n";
    }
    br.readLine();
    if (addNew)
      mService.addNewVPNProfile("nonEditable", false, config);
    else
      mService.startVPN(config);
  } catch (IOException | RemoteException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: mayubao/KuaiChuan

InputStream is = this.mActivity.getAssets().open("index.html");
indexHtml = IOStreamUtils.inputStreamToString(is);

代码示例来源:origin: mayubao/KuaiChuan

/**
 * 获取指定文件类型的的html字符串
 * @param fieInfos
 * @throws IOException
 */
private String getFileInfoListHtml(List<FileInfo> fieInfos) throws IOException {
  StringBuilder sb = new StringBuilder();
  for(FileInfo fileInfo : fieInfos){
    String fileInfoHtml = IOStreamUtils.inputStreamToString(sActivity.getAssets().open(Constant.NAME_FILE_TEMPLATE));
    fileInfoHtml = fileInfoHtml.replaceAll("\\{file_avatar\\}", IMAGE_PREFIX + FileUtils.getFileName(fileInfo.getFilePath()));
    fileInfoHtml = fileInfoHtml.replaceAll("\\{file_name\\}", FileUtils.getFileName(fileInfo.getFilePath()));
    fileInfoHtml = fileInfoHtml.replaceAll("\\{file_size\\}", FileUtils.getFileSize(fileInfo.getSize()));
    fileInfoHtml = fileInfoHtml.replaceAll("\\{file_path\\}", DOWNLOAD_PREFIX + FileUtils.getFileName(fileInfo.getFilePath()));
    sb.append(fileInfoHtml);
  }
  return sb.toString();
}

代码示例来源:origin: com.uphyca/android-junit4-robolectric

/**
 * @return
 * @see android.content.ContextWrapper#getAssets()
 */
public AssetManager getAssets() {
  return mActivity.getAssets();
}

代码示例来源:origin: iqiyi/Neptune

@Override
public AssetManager getAssets() {
  if (mLoadedApk == null) {
    return super.getAssets();
  }
  AssetManager mPluginAssetManager = mLoadedApk.getPluginAssetManager();
  return mPluginAssetManager == null ? super.getAssets()
      : mPluginAssetManager;
}

代码示例来源:origin: qdxxxx/IndexBarLayout

public CarBean readFromAssets(Activity activity) {
  CarBean carBean = null;
  try {
    InputStream is = activity.getAssets().open("cars.json");//此处为要加载的json文件名称
    String text = readTextFromSDcard(is);
    carBean = new Gson().fromJson(text, CarBean.class);
  } catch (Exception e) {
    e.printStackTrace();
  }
  return carBean;
}

代码示例来源:origin: novoda/spikes

/**
 * Reads label list from Assets.
 */
private List<String> loadLabelList(Activity activity) throws IOException {
  List<String> labelList = new ArrayList<String>();
  BufferedReader reader =
      new BufferedReader(new InputStreamReader(activity.getAssets().open(getLabelPath())));
  String line;
  while ((line = reader.readLine()) != null) {
    labelList.add(line);
  }
  reader.close();
  return labelList;
}

代码示例来源:origin: lawloretienne/Trestle

@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  italicFont = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Roboto-Italic.ttf");
  regularFont = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Roboto-Regular.ttf");
  boldItalicFont = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Roboto-BoldItalic.ttf");
}

代码示例来源:origin: wordpress-mobile/WordPress-Editor-Android

public static String getHtmlFromFile(Activity activity, String filename) {
  try {
    AssetManager assetManager = activity.getAssets();
    InputStream in = assetManager.open(filename);
    return getStringFromInputStream(in);
  } catch (IOException e) {
    AppLog.e(AppLog.T.EDITOR, "Unable to load editor HTML (is the assets symlink working?): " + e.getMessage());
    return null;
  }
}

代码示例来源:origin: stackoverflow.com

public static void applyFontForToolbarTitle(Activity context){
  Toolbar toolbar = (Toolbar) context.findViewById(R.id.app_bar);
  for(int i = 0; i < toolbar.getChildCount(); i++){
    View view = toolbar.getChildAt(i);
    if(view instanceof TextView){
      TextView tv = (TextView) view;
      Typeface titleFont = Typeface.
        createFromAsset(context.getAssets(), "fonts/customFont");
      if(tv.getText().equals(context.getTitle())){
        tv.setTypeface(titleFont);
        break;
      }
    }
  }
}

代码示例来源:origin: stackoverflow.com

public static void applyFontForToolbarTitle(Activity context){
  Toolbar toolbar = (Toolbar) context.findViewById(R.id.app_bar);
  for(int i = 0; i < toolbar.getChildCount(); i++){
    View view = toolbar.getChildAt(i);
    if(view instanceof TextView){
      TextView tv = (TextView) view;
      Typeface titleFont = Typeface.
        createFromAsset(context.getAssets(), "fonts/customFont");
      if(tv.getText().equals(context.getTitle())){
        tv.setTypeface(titleFont);
        break;
      }
    }
  }
}

代码示例来源:origin: stackoverflow.com

public static void applyFontForToolbarTitle(Activity context){
  Toolbar toolbar = (Toolbar) context.findViewById(R.id.app_bar);
  for(int i = 0; i < toolbar.getChildCount(); i++){
    View view = toolbar.getChildAt(i);
    if(view instanceof TextView){
      TextView tv = (TextView) view;
      Typeface titleFont = Typeface.
        createFromAsset(context.getAssets(), "fonts/customFont");
      if(tv.getText().equals(context.getTitle())){
        tv.setTypeface(titleFont);
        break;
      }
    }
  }
}

代码示例来源:origin: stackoverflow.com

public static void applyFontForToolbarTitle(Activity context){
  Toolbar toolbar = (Toolbar) context.findViewById(R.id.app_bar);
  for(int i = 0; i < toolbar.getChildCount(); i++){
    View view = toolbar.getChildAt(i);
    if(view instanceof TextView){
      TextView tv = (TextView) view;
      Typeface titleFont = Typeface.
        createFromAsset(context.getAssets(), "fonts/customFont");
      if(tv.getText().equals(context.getTitle())){
        tv.setTypeface(titleFont);
        break;
      }
    }
  }
}

代码示例来源:origin: novoda/spikes

/**
 * Memory-map the model file in Assets.
 */
private MappedByteBuffer loadModelFile(Activity activity) throws IOException {
  AssetFileDescriptor fileDescriptor = activity.getAssets().openFd(getModelPath());
  FileInputStream inputStream = new FileInputStream(fileDescriptor.getFileDescriptor());
  FileChannel fileChannel = inputStream.getChannel();
  long startOffset = fileDescriptor.getStartOffset();
  long declaredLength = fileDescriptor.getDeclaredLength();
  return fileChannel.map(FileChannel.MapMode.READ_ONLY, startOffset, declaredLength);
}

代码示例来源:origin: gearvrf/GearVRf-Demos

private GVRVideoSceneObject createVideoObject(GVRContext gvrContext) throws IOException {
  final AssetFileDescriptor afd = gvrContext.getActivity().getAssets().openFd("tron.mp4");
  final MediaPlayer mediaPlayer = new MediaPlayer();
  mediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
  mediaPlayer.prepare();
  GVRVideoSceneObject video = new GVRVideoSceneObject(gvrContext, 8.0f,
      4.0f, mediaPlayer, GVRVideoType.MONO);
  video.setName("video");
  return video;
}

代码示例来源:origin: stackoverflow.com

public static ActionBar setCustomActionBar(Activity activity, ActionBar actionBar, String title) {
    if (actionBar != null) {
      ViewGroup actionBarLayout = (ViewGroup) activity.getLayoutInflater().inflate(R.layout.custom_actionbar, null);

      actionBar.setDisplayShowHomeEnabled(false);
      actionBar.setDisplayShowTitleEnabled(false);
      actionBar.setDisplayShowCustomEnabled(true);
      actionBar.setCustomView(actionBarLayout);
      actionBar.setBackgroundDrawable(new ColorDrawable(activity.getResources().getColor(R.color.actionbar_grey)));

      TextView actionBarTitle = (TextView) actionBarLayout.findViewById(R.id.text_actionbar_title);
      Typeface airplaneTypeface = Typeface.createFromAsset(activity.getAssets(), "fonts/Exo-Regular.otf");
      actionBarTitle.setText(title);
      actionBarTitle.setTypeface(airplaneTypeface);

//        SpannableString s = new SpannableString(title);
//        s.setSpan(new TypefaceSpan(activity, "fonts/airplane.ttf"), 0, s.length(),
//                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//        actionBar.setTitle(s);
    }
    return actionBar;
  }

相关文章

微信公众号

最新文章

更多

Activity类方法