Java Code Examples for android.text.format.Formatter

The following are top voted examples for showing how to use android.text.format.Formatter. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Tiny   File: BatchBitmapCompressTestActivity.java   Source Code and License 6 votes vote down vote up
private void setupOriginInfo(Bitmap bitmap1, Bitmap bitmap2, Bitmap bitmap3, Bitmap bitmap4) {
    mOriginImg1.setImageBitmap(bitmap1);
    mOriginImg2.setImageBitmap(bitmap2);
    mOriginImg3.setImageBitmap(bitmap3);
    mOriginImg4.setImageBitmap(bitmap4);
    mOriginTv.setText("origin bitmap memory size:\nbitmap[1,2,3,4]:" + Formatter.formatFileSize(this, bitmap1.getByteCount())
            + "," + Formatter.formatFileSize(this, bitmap2.getByteCount())
            + "," + Formatter.formatFileSize(this, bitmap3.getByteCount())
            + "," + Formatter.formatFileSize(this, bitmap4.getByteCount())
            + "\nwidth[1,2,3,4]:" + bitmap1.getWidth()
            + "," + bitmap2.getWidth()
            + "," + bitmap3.getWidth()
            + "," + bitmap4.getWidth()
            + "\nheight[1,2,3,4]:" + bitmap1.getHeight()
            + "," + bitmap2.getHeight()
            + "," + bitmap3.getHeight()
            + "," + bitmap4.getHeight()
            + "\nconfig:" + mConfig);
}
 
Example 2
Project: Tiny   File: BatchFileWithReturnBitmapCompressTestActivity.java   Source Code and License 6 votes vote down vote up
private void setupCompressInfo(
        Bitmap bitmap1, Bitmap bitmap2, Bitmap bitmap3, Bitmap bitmap4,
        String outfile1, String outfile2, String outfile3, String outfile4,
        long sizeBytes1, long sizeBytes2, long sizeBytes3, long sizeBytes4) {
    mCompressImg1.setImageBitmap(bitmap1);
    mCompressImg2.setImageBitmap(bitmap2);
    mCompressImg3.setImageBitmap(bitmap3);
    mCompressImg4.setImageBitmap(bitmap4);
    mCompressTv.setText("compress file size:\nfile[1,2,3,4]:" + Formatter.formatFileSize(this, sizeBytes1)
            + "," + Formatter.formatFileSize(this, sizeBytes2)
            + "," + Formatter.formatFileSize(this, sizeBytes3)
            + "," + Formatter.formatFileSize(this, sizeBytes4)
            + "\nwidth[1,2,3,4]:" + bitmap1.getWidth()
            + "," + bitmap2.getWidth()
            + "," + bitmap3.getWidth()
            + "," + bitmap4.getWidth()
            + "\nheight[1,2,3,4]:" + bitmap1.getHeight()
            + "," + bitmap2.getHeight()
            + "," + bitmap3.getHeight()
            + "," + bitmap4.getHeight()
            + "\n\noutfile1:" + outfile1
            + "\n\noutfile2:" + outfile2
            + "\n\noutfile3:" + outfile3
            + "\n\noutfile4:" + outfile4
            + "\n\nconfig:" + mConfig);
}
 
Example 3
Project: BadIntent   File: BadIntentPreferencesActivity.java   Source Code and License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //try to set this WiFi IP (in case there is no [valid] value set yet)
    WifiManager wm = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
    String wifiIP = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());
    SharedPreferences sPrefs = getSharedPreferences(AppAnalyzer.PREFNAME, MODE_WORLD_READABLE);
    String target_ip = sPrefs.getString(BadIntentConstants.TARGET_IP, " ");
    if (target_ip.equals(" ") || target_ip.equals("0.0.0.0")) {
        sPrefs.edit()
                .putString(BadIntentConstants.TARGET_IP, wifiIP)
                .apply();
    }
    addPreferencesFromResource(R.xml.bad_intent_preferences);

}
 
Example 4
Project: Tiny   File: BatchFileCompressTestActivity.java   Source Code and License 6 votes vote down vote up
private void setupOriginInfo(Bitmap bitmap1, Bitmap bitmap2, Bitmap bitmap3, Bitmap bitmap4
        , long sizeBytes1, long sizeBytes2, long sizeBytes3, long sizeBytes4) {
    mOriginImg1.setImageBitmap(bitmap1);
    mOriginImg2.setImageBitmap(bitmap2);
    mOriginImg3.setImageBitmap(bitmap3);
    mOriginImg4.setImageBitmap(bitmap4);

    mOriginTv.setText("origin file size:\nfile[1,2,3,4]:" + Formatter.formatFileSize(this, sizeBytes1)
            + "," + Formatter.formatFileSize(this, sizeBytes2)
            + "," + Formatter.formatFileSize(this, sizeBytes3)
            + "," + Formatter.formatFileSize(this, sizeBytes4)
            + "\nwidth[1,2,3,4]:" + bitmap1.getWidth()
            + "," + bitmap2.getWidth()
            + "," + bitmap3.getWidth()
            + "," + bitmap4.getWidth()
            + "\nheight[1,2,3,4]:" + bitmap1.getHeight()
            + "," + bitmap2.getHeight()
            + "," + bitmap3.getHeight()
            + "," + bitmap4.getHeight()
            + "\nconfig:" + mConfig);
}
 
Example 5
Project: RLibrary   File: Luban.java   Source Code and License 6 votes vote down vote up
public static void logFileItems(Context context, ArrayList<ImageItem> files) {
    if (files == null) {
        return;
    }
    for (ImageItem s : files) {
        File originFile = new File(s.path);
        File thumbFile = new File(s.thumbPath);
        StringBuilder stringBuilder = new StringBuilder("\n");
        if (originFile.exists()) {
            stringBuilder.append("原始:");
            stringBuilder.append(originFile.getAbsolutePath());
            stringBuilder.append(" ");
            stringBuilder.append(Formatter.formatFileSize(context, originFile.length()));
            stringBuilder.append("\n");
        }
        if (thumbFile.exists()) {
            stringBuilder.append("压缩:");
            stringBuilder.append(thumbFile.getAbsolutePath());
            stringBuilder.append(" ");
            stringBuilder.append(Formatter.formatFileSize(context, thumbFile.length()));
            stringBuilder.append("\n");
        }
        L.e(stringBuilder.toString());
    }
}
 
Example 6
Project: AndroidBasicLibs   File: MemoryCache.java   Source Code and License 6 votes vote down vote up
/**
 * Get total memory
 *
 * @param context
 * @return
 */
public static String getTotalMemory(Context context) {
    String str1 = "/proc/meminfo";
    String str2;
    String[] arrayOfString;
    long initial_memory = 0;
    try {
        FileReader localFileReader = new FileReader(str1);
        BufferedReader localBufferedReader = new BufferedReader(localFileReader, 8192);
        str2 = localBufferedReader.readLine();
        arrayOfString = str2.split("\\s+");
        for (String num : arrayOfString) {
            Log.i(str2, num + "\t");
        }
        initial_memory = Integer.valueOf(arrayOfString[1]).intValue() * 1024;
        localBufferedReader.close();

    } catch (IOException e) {
        e.printStackTrace();
    }
    return Formatter.formatFileSize(context, initial_memory);// Byte转换为KB或者MB,内存大小规格化
}
 
Example 7
Project: RLibrary   File: ImagePreviewActivity.java   Source Code and License 6 votes vote down vote up
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    int id = buttonView.getId();
    if (id == R.id.cb_origin) {
        if (isChecked) {
            long size = 0;
            for (ImageItem item : selectedImages)
                size += item.size;
            String fileSize = Formatter.formatFileSize(this, size);
            isOrigin = true;
            mCbOrigin.setText(getString(R.string.origin_size, fileSize));
        } else {
            isOrigin = false;
            mCbOrigin.setText(getString(R.string.origin));
        }
    }
}
 
Example 8
Project: Auto.js   File: WifiTool.java   Source Code and License 6 votes vote down vote up
public static String getWifiAddress(Context context) {
    WifiManager wifiMgr = (WifiManager) context.getApplicationContext().getSystemService(WIFI_SERVICE);
    if(wifiMgr == null){
        return null;
    }
    WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
    int ip = wifiInfo.getIpAddress();
    return Formatter.formatIpAddress(ip);
}
 
Example 9
Project: Java-9-Programming-Blueprints   File: DeskDroidService.java   Source Code and License 6 votes vote down vote up
protected void startServer() {
        WifiManager wifiMgr = (WifiManager) getApplicationContext()
                .getSystemService(Service.WIFI_SERVICE);
        if (wifiMgr.isWifiEnabled()) {
            // Deprecated. Does not support ipv6. *shrug* :)
            String ipAddress = Formatter.formatIpAddress(wifiMgr.getConnectionInfo()
                    .getIpAddress());

            URI baseUri = UriBuilder.fromUri("http://" + ipAddress)
                    .port(49152)
                    .build();
            ResourceConfig config = new ResourceConfig(SseFeature.class)
                    .register(JacksonFeature.class);
            config.registerInstances(new SecureFilter(this));
            config.registerInstances(new DeskDroidResource(this));
//            server = JettyHttpContainerFactory.createServer(baseUri, config);
            server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config);
        }
    }
 
Example 10
Project: FakeWeather   File: FileSizeUtil.java   Source Code and License 6 votes vote down vote up
public static String getAutoFileOrFilesSize(String... filePaths) {
    long totalSize = 0;
    for (String filePath : filePaths) {
        File file = new File(filePath);
        long blockSize = 0;
        try {
            if (file.isDirectory()) {
                blockSize = getFileSizes(file);
            } else {
                blockSize = getFileSize(file);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        totalSize = totalSize + blockSize;
    }
    return Formatter.formatFileSize(App.getContext(), totalSize);
}
 
Example 11
Project: aos-Video   File: Paste.java   Source Code and License 6 votes vote down vote up
@Override
public void onProgressUpdate() {
    FileManagerService service = FileManagerService.fileManagerService;

        if(service.getPasteTotalSize()>0)
            mProgress.setProgress((int) (MAX_PROGRESS *  service.getPasteTotalProgress() / service.getPasteTotalSize()));
        if( service.getPasteTotalProgress() != service.getPasteTotalSize()){
            if(service.getFilesToPaste().size()>0) {
                setMessage(service.getFilesToPaste().get(service.getCurrentFile()).getName());
                if (service.getFilesToPaste().size() > 1) {
                    mProgressText.setText(mContext.getResources().getString(com.archos.filecorelibrary.R.string.pasting_copy_many,
                            service.getCurrentFile()+1, service.getFilesToPaste().size(),
                            Formatter.formatShortFileSize(mContext, service.getPasteTotalProgress()), Formatter.formatShortFileSize(mContext, service.getPasteTotalSize())));
                } else {
                    mProgressText.setText(mContext.getResources().getString(com.archos.filecorelibrary.R.string.pasting_copy_one,
                            Formatter.formatShortFileSize(mContext, service.getPasteTotalProgress()), Formatter.formatShortFileSize(mContext, service.getPasteTotalSize())));
                }
            }
        }
        else
            mProgressText.setText(mContext.getResources().getString(com.archos.filecorelibrary.R.string.pasting_done));


}
 
Example 12
Project: SDCardCleaner   File: SDCardPercent.java   Source Code and License 6 votes vote down vote up
/**
 * 刷新数据
 */
public void refresh() {
    long _space_free = Environment.getExternalStorageDirectory().getFreeSpace();
    long _fileCount_all = Global.get_fileCount_all();
    long _fileSize_all = Global.get_fileSize_all();
    long _fileCount_rubbish = Global.get_fileCount_rubbish();
    long _fileSize_rubbish = Global.get_fileSize_rubbish();

    TransitionManager.beginDelayedTransition(_line);
    _set_line.setGuidelinePercent(R.id.guideLine_rubbish, (float) NumberUtil.div(_fileSize_rubbish, _space_total, 3));
    _set_line.setGuidelinePercent(R.id.guideLine_file, (float) NumberUtil.div(_fileSize_all, _space_total, 3));
    _set_line.setGuidelinePercent(R.id.guideLine_system, (float) (1 - NumberUtil.div(_space_free, _space_total, 3)));
    _set_line.applyTo(_line);

    _text_system.setText(getContext().getString(R.string.state_fileCount_system, Formatter.formatFileSize(getContext(), _space_total - _space_free - _fileSize_all)));
    _text_blank.setText(getContext().getString(R.string.state_fileCount_blank, Formatter.formatFileSize(getContext(), _space_free)));
    _text_file.setText(getContext().getString(R.string.state_fileCount_file, Formatter.formatFileSize(getContext(), _fileSize_all), _fileCount_all));
    _text_rubbish.setText(getContext().getString(R.string.state_fileCount_rubbish, Formatter.formatFileSize(getContext(), _fileSize_rubbish), _fileCount_rubbish));
}
 
Example 13
Project: buildAPKsSamples   File: WifiInfoActivity.java   Source Code and License 6 votes vote down vote up
public void onClick(View v) {
    out.setText("");

    out.append("\n\nConfigured Networks:");
    // Get IP Address
    int ipAddress = wifimanager.getConnectionInfo().getIpAddress();
    out.append("\nThe ip address is "
            + Formatter.formatIpAddress(ipAddress));

    // Get configured networks
    List<WifiConfiguration> configuredNetworks = wifimanager.getConfiguredNetworks();
    for (WifiConfiguration conf : configuredNetworks) {
        out.append(String.format("\n%s", conf.SSID));
    }

    wifimanager.startScan();
}
 
Example 14
Project: postixdroid   File: MainActivity.java   Source Code and License 6 votes vote down vote up
private void show_network_info() {
    WifiManager wm = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
    String ip = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());
    String mac = wm.getConnectionInfo().getMacAddress();

    StringBuilder sb = new StringBuilder();
    sb.append("WiFi IP address: ");
    sb.append(ip);
    sb.append("\nWiFi MAC address: ");
    sb.append(mac);
    final AlertDialog dialog = new AlertDialog.Builder(this)
            .setTitle(R.string.networkinfo)
            .setMessage(sb.toString())
            .setPositiveButton(R.string.dismiss, null)
            .create();
    dialog.show();
}
 
Example 15
Project: tiny   File: BatchFileWithReturnBitmapCompressTestActivity.java   Source Code and License 6 votes vote down vote up
private void setupOriginInfo(Bitmap bitmap1, Bitmap bitmap2, Bitmap bitmap3, Bitmap bitmap4
        , long sizeBytes1, long sizeBytes2, long sizeBytes3, long sizeBytes4) {
    mOriginImg1.setImageBitmap(bitmap1);
    mOriginImg2.setImageBitmap(bitmap2);
    mOriginImg3.setImageBitmap(bitmap3);
    mOriginImg4.setImageBitmap(bitmap4);

    mOriginTv.setText("origin file size:\nfile[1,2,3,4]:" + Formatter.formatFileSize(this, sizeBytes1)
            + "," + Formatter.formatFileSize(this, sizeBytes2)
            + "," + Formatter.formatFileSize(this, sizeBytes3)
            + "," + Formatter.formatFileSize(this, sizeBytes4)
            + "\nwidth[1,2,3,4]:" + bitmap1.getWidth()
            + "," + bitmap2.getWidth()
            + "," + bitmap3.getWidth()
            + "," + bitmap4.getWidth()
            + "\nheight[1,2,3,4]:" + bitmap1.getHeight()
            + "," + bitmap2.getHeight()
            + "," + bitmap3.getHeight()
            + "," + bitmap4.getHeight()
            + "\nconfig:" + mConfig);
}
 
Example 16
Project: tiny   File: BatchFileWithReturnBitmapCompressTestActivity.java   Source Code and License 6 votes vote down vote up
private void setupCompressInfo(
        Bitmap bitmap1, Bitmap bitmap2, Bitmap bitmap3, Bitmap bitmap4,
        String outfile1, String outfile2, String outfile3, String outfile4,
        long sizeBytes1, long sizeBytes2, long sizeBytes3, long sizeBytes4) {
    mCompressImg1.setImageBitmap(bitmap1);
    mCompressImg2.setImageBitmap(bitmap2);
    mCompressImg3.setImageBitmap(bitmap3);
    mCompressImg4.setImageBitmap(bitmap4);
    mCompressTv.setText("compress file size:\nfile[1,2,3,4]:" + Formatter.formatFileSize(this, sizeBytes1)
            + "," + Formatter.formatFileSize(this, sizeBytes2)
            + "," + Formatter.formatFileSize(this, sizeBytes3)
            + "," + Formatter.formatFileSize(this, sizeBytes4)
            + "\nwidth[1,2,3,4]:" + bitmap1.getWidth()
            + "," + bitmap2.getWidth()
            + "," + bitmap3.getWidth()
            + "," + bitmap4.getWidth()
            + "\nheight[1,2,3,4]:" + bitmap1.getHeight()
            + "," + bitmap2.getHeight()
            + "," + bitmap3.getHeight()
            + "," + bitmap4.getHeight()
            + "\n\noutfile1:" + outfile1
            + "\n\noutfile2:" + outfile2
            + "\n\noutfile3:" + outfile3
            + "\n\noutfile4:" + outfile4
            + "\n\nconfig:" + mConfig);
}
 
Example 17
Project: tiny   File: BatchBitmapCompressTestActivity.java   Source Code and License 6 votes vote down vote up
private void setupOriginInfo(Bitmap bitmap1, Bitmap bitmap2, Bitmap bitmap3, Bitmap bitmap4) {
    mOriginImg1.setImageBitmap(bitmap1);
    mOriginImg2.setImageBitmap(bitmap2);
    mOriginImg3.setImageBitmap(bitmap3);
    mOriginImg4.setImageBitmap(bitmap4);
    mOriginTv.setText("origin bitmap memory size:\nbitmap[1,2,3,4]:" + Formatter.formatFileSize(this, bitmap1.getByteCount())
            + "," + Formatter.formatFileSize(this, bitmap2.getByteCount())
            + "," + Formatter.formatFileSize(this, bitmap3.getByteCount())
            + "," + Formatter.formatFileSize(this, bitmap4.getByteCount())
            + "\nwidth[1,2,3,4]:" + bitmap1.getWidth()
            + "," + bitmap2.getWidth()
            + "," + bitmap3.getWidth()
            + "," + bitmap4.getWidth()
            + "\nheight[1,2,3,4]:" + bitmap1.getHeight()
            + "," + bitmap2.getHeight()
            + "," + bitmap3.getHeight()
            + "," + bitmap4.getHeight()
            + "\nconfig:" + mConfig);
}
 
Example 18
Project: tiny   File: BatchBitmapCompressTestActivity.java   Source Code and License 6 votes vote down vote up
private void setupCompressInfo(Bitmap bitmap1, Bitmap bitmap2, Bitmap bitmap3, Bitmap bitmap4) {
    mCompressImg1.setImageBitmap(bitmap1);
    mCompressImg2.setImageBitmap(bitmap2);
    mCompressImg3.setImageBitmap(bitmap3);
    mCompressImg4.setImageBitmap(bitmap4);
    mCompressTv.setText("compress bitmap memory size:\nbitmap[1,2,3,4]:" + Formatter.formatFileSize(this, bitmap1.getByteCount())
            + "," + Formatter.formatFileSize(this, bitmap2.getByteCount())
            + "," + Formatter.formatFileSize(this, bitmap3.getByteCount())
            + "," + Formatter.formatFileSize(this, bitmap4.getByteCount())
            + "\nwidth[1,2,3,4]:" + bitmap1.getWidth()
            + "," + bitmap2.getWidth()
            + "," + bitmap3.getWidth()
            + "," + bitmap4.getWidth()
            + "\nheight[1,2,3,4]:" + bitmap1.getHeight()
            + "," + bitmap2.getHeight()
            + "," + bitmap3.getHeight()
            + "," + bitmap4.getHeight()
            + "\nconfig:" + mConfig);
}
 
Example 19
Project: RLibrary   File: ImagePreviewActivity.java   Source Code and License 6 votes vote down vote up
/**
 * 图片添加成功后,修改当前图片的选中数量
 * 当调用 addSelectedImageItem 或 deleteSelectedImageItem 都会触发当前回调
 */
@Override
public void onImageSelected(int position, ImageItem item, boolean isAdd) {
    if (imagePicker.getSelectImageCount() > 0) {
        mBtnOk.setText(getString(R.string.select_complete, imagePicker.getSelectImageCount(), imagePicker.getSelectLimit()));
        mBtnOk.setEnabled(true);
    } else {
        mBtnOk.setText(getString(R.string.complete));
        mBtnOk.setEnabled(false);
    }

    if (mCbOrigin.isChecked()) {
        long size = 0;
        for (ImageItem imageItem : selectedImages)
            size += imageItem.size;
        String fileSize = Formatter.formatFileSize(this, size);
        mCbOrigin.setText(getString(R.string.origin_size, fileSize));
    }
}
 
Example 20
Project: aos-MediaLib   File: InfoDialog.java   Source Code and License 6 votes vote down vote up
public void handleMessage(Message msg) {
    if (msg.what == MSG_SIZE_COMPUTED) {
        ArrayList<Object> list = (ArrayList<Object>) msg.obj;
        if (msg.arg1 == -1 && msg.arg2 == -1) {
            // Size is computed, hide the progressbar
            ProgressBar pb = (ProgressBar) list.get(1);
            pb.setVisibility(View.GONE);
        } else {
            // Size is beeing computed => display the current total
            TextView sizeTv = (TextView) list.get(0);
            TextView numberFilesTv = (TextView) list.get(2);
            sizeTv.setText(Formatter.formatFileSize(mC, (Long) list.get(3)));
            if (msg.arg1 == 0 && msg.arg2 == 0) {
                numberFilesTv.setText(R.string.file_info_directory_empty);
            } else {
                numberFilesTv.setText(InfoDialog.formatDirectoryInfo(mC, msg.arg1,
                        msg.arg2));
            }
        }
    }
}
 
Example 21
Project: Tiny   File: BatchBitmapCompressTestActivity.java   Source Code and License 6 votes vote down vote up
private void setupCompressInfo(Bitmap bitmap1, Bitmap bitmap2, Bitmap bitmap3, Bitmap bitmap4) {
    mCompressImg1.setImageBitmap(bitmap1);
    mCompressImg2.setImageBitmap(bitmap2);
    mCompressImg3.setImageBitmap(bitmap3);
    mCompressImg4.setImageBitmap(bitmap4);
    mCompressTv.setText("compress bitmap memory size:\nbitmap[1,2,3,4]:" + Formatter.formatFileSize(this, bitmap1.getByteCount())
            + "," + Formatter.formatFileSize(this, bitmap2.getByteCount())
            + "," + Formatter.formatFileSize(this, bitmap3.getByteCount())
            + "," + Formatter.formatFileSize(this, bitmap4.getByteCount())
            + "\nwidth[1,2,3,4]:" + bitmap1.getWidth()
            + "," + bitmap2.getWidth()
            + "," + bitmap3.getWidth()
            + "," + bitmap4.getWidth()
            + "\nheight[1,2,3,4]:" + bitmap1.getHeight()
            + "," + bitmap2.getHeight()
            + "," + bitmap3.getHeight()
            + "," + bitmap4.getHeight()
            + "\nconfig:" + mConfig);
}
 
Example 22
Project: lineagex86   File: IncreasingRingVolumePreference.java   Source Code and License 5 votes vote down vote up
@Override
protected void onBindView(View view) {
    super.onBindView(view);
    getPreferenceManager().registerOnActivityStopListener(this);

    initHandler();

    final SeekBar seekBar = (SeekBar) view.findViewById(R.id.start_volume);
    if (seekBar == mStartVolumeSeekBar) return;

    mStartVolumeSeekBar = seekBar;
    mRampUpTimeSeekBar = (SeekBar) view.findViewById(R.id.ramp_up_time);
    mRampUpTimeValue = (TextView) view.findViewById(R.id.ramp_up_time_value);

    final ContentResolver cr = getContext().getContentResolver();
    float startVolume = CMSettings.System.getFloat(cr,
            CMSettings.System.INCREASING_RING_START_VOLUME, 0.1f);
    int rampUpTime = CMSettings.System.getInt(cr,
            CMSettings.System.INCREASING_RING_RAMP_UP_TIME, 10);

    mStartVolumeSeekBar.setProgress(Math.round(startVolume * 1000F));
    mStartVolumeSeekBar.setOnSeekBarChangeListener(this);
    mRampUpTimeSeekBar.setOnSeekBarChangeListener(this);
    mRampUpTimeSeekBar.setProgress((rampUpTime / 5) - 1);
    mRampUpTimeValue.setText(
            Formatter.formatShortElapsedTime(getContext(), rampUpTime * 1000));
}
 
Example 23
Project: lineagex86   File: IncreasingRingVolumePreference.java   Source Code and License 5 votes vote down vote up
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
    ContentResolver cr = getContext().getContentResolver();
    if (fromTouch && seekBar == mStartVolumeSeekBar) {
        CMSettings.System.putFloat(cr, CMSettings.System.INCREASING_RING_START_VOLUME,
                    (float) progress / 1000F);
    } else if (seekBar == mRampUpTimeSeekBar) {
        int seconds = (progress + 1) * 5;
        mRampUpTimeValue.setText(
                Formatter.formatShortElapsedTime(getContext(), seconds * 1000));
        if (fromTouch) {
            CMSettings.System.putInt(cr,
                    CMSettings.System.INCREASING_RING_RAMP_UP_TIME, seconds);
        }
    }
}
 
Example 24
Project: GitHub   File: DeviceUtils.java   Source Code and License 5 votes vote down vote up
/**
 * 获取系统当前可用内存大小
 *
 * @param context
 * @return
 */
@TargetApi(Build.VERSION_CODES.CUPCAKE)
public static String getAvailMemory(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
    am.getMemoryInfo(mi);
    return Formatter.formatFileSize(context, mi.availMem);// 将获取的内存大小规格化
}
 
Example 25
Project: GitHub   File: UploadAdapter.java   Source Code and License 5 votes vote down vote up
public void refresh(Progress progress) {
    String currentSize = Formatter.formatFileSize(context, progress.currentSize);
    String totalSize = Formatter.formatFileSize(context, progress.totalSize);
    downloadSize.setText(currentSize + "/" + totalSize);
    priority.setText(String.format("优先级:%s", progress.priority));
    switch (progress.status) {
        case Progress.NONE:
            netSpeed.setText("停止");
            upload.setText("上传");
            break;
        case Progress.PAUSE:
            netSpeed.setText("暂停中");
            upload.setText("继续");
            break;
        case Progress.ERROR:
            netSpeed.setText("上传出错");
            upload.setText("出错");
            break;
        case Progress.WAITING:
            netSpeed.setText("等待中");
            upload.setText("等待");
            break;
        case Progress.FINISH:
            upload.setText("完成");
            netSpeed.setText("上传成功");
            break;
        case Progress.LOADING:
            String speed = Formatter.formatFileSize(context, progress.speed);
            netSpeed.setText(String.format("%s/s", speed));
            upload.setText("停止");
            break;
    }
    tvProgress.setText(numberFormat.format(progress.fraction));
    pbProgress.setMax(10000);
    pbProgress.setProgress((int) (progress.fraction * 10000));
}
 
Example 26
Project: GitHub   File: DownloadAdapter.java   Source Code and License 5 votes vote down vote up
public void refresh(Progress progress) {
    String currentSize = Formatter.formatFileSize(context, progress.currentSize);
    String totalSize = Formatter.formatFileSize(context, progress.totalSize);
    downloadSize.setText(currentSize + "/" + totalSize);
    priority.setText(String.format("优先级:%s", progress.priority));
    switch (progress.status) {
        case Progress.NONE:
            netSpeed.setText("停止");
            download.setText("下载");
            break;
        case Progress.PAUSE:
            netSpeed.setText("暂停中");
            download.setText("继续");
            break;
        case Progress.ERROR:
            netSpeed.setText("下载出错");
            download.setText("出错");
            break;
        case Progress.WAITING:
            netSpeed.setText("等待中");
            download.setText("等待");
            break;
        case Progress.FINISH:
            netSpeed.setText("下载完成");
            download.setText("完成");
            break;
        case Progress.LOADING:
            String speed = Formatter.formatFileSize(context, progress.speed);
            netSpeed.setText(String.format("%s/s", speed));
            download.setText("暂停");
            break;
    }
    tvProgress.setText(numberFormat.format(progress.fraction));
    pbProgress.setMax(10000);
    pbProgress.setProgress((int) (progress.fraction * 10000));
}
 
Example 27
Project: GitHub   File: DesActivity.java   Source Code and License 5 votes vote down vote up
private void refreshUi(Progress progress) {
    String currentSize = Formatter.formatFileSize(this, progress.currentSize);
    String totalSize = Formatter.formatFileSize(this, progress.totalSize);
    downloadSize.setText(currentSize + "/" + totalSize);
    String speed = Formatter.formatFileSize(this, progress.speed);
    netSpeed.setText(String.format("%s/s", speed));
    tvProgress.setText(numberFormat.format(progress.fraction));
    pbProgress.setMax(10000);
    pbProgress.setProgress((int) (progress.fraction * 10000));
    switch (progress.status) {
        case Progress.NONE:
            download.setText("下载");
            break;
        case Progress.LOADING:
            download.setText("暂停");
            break;
        case Progress.PAUSE:
            download.setText("继续");
            break;
        case Progress.WAITING:
            download.setText("等待");
            break;
        case Progress.ERROR:
            download.setText("出错");
            break;
        case Progress.FINISH:
            if (ApkUtils.isAvailable(this, new File(progress.filePath))) {
                download.setText("卸载");
            } else {
                download.setText("安装");
            }
            break;
    }
}
 
Example 28
Project: stynico   File: SimpleActivity.java   Source Code and License 5 votes vote down vote up
private String getSDTotalSize()
{
       File path = Environment.getExternalStorageDirectory();
       StatFs stat = new StatFs(path.getPath());
       long blockSize = stat.getBlockSize();
       long totalBlocks = stat.getBlockCount();
       return Formatter.formatFileSize(SimpleActivity.this, blockSize * totalBlocks);
   }
 
Example 29
Project: stynico   File: SimpleActivity.java   Source Code and License 5 votes vote down vote up
/**
    * 获得sd卡剩余容量,即可用大小
    *
    * @return
    */
   private String getSDAvailableSize()
{
       File path = Environment.getExternalStorageDirectory();
       StatFs stat = new StatFs(path.getPath());
       long blockSize = stat.getBlockSize();
       long availableBlocks = stat.getAvailableBlocks();
       return Formatter.formatFileSize(SimpleActivity.this, blockSize * availableBlocks);
   }
 
Example 30
Project: stynico   File: SimpleActivity.java   Source Code and License 5 votes vote down vote up
/**
    * 获得机身内存总大小
    *
    * @return
    */
   private String getRomTotalSize()
{
       File path = Environment.getDataDirectory();
       StatFs stat = new StatFs(path.getPath());
       long blockSize = stat.getBlockSize();
       long totalBlocks = stat.getBlockCount();
       return Formatter.formatFileSize(SimpleActivity.this, blockSize * totalBlocks);
   }
 
Example 31
Project: stynico   File: SimpleActivity.java   Source Code and License 5 votes vote down vote up
/**
    * 获得机身可用内存
    *
    * @return
    */
   private String getRomAvailableSize()
{
       File path = Environment.getDataDirectory();
       StatFs stat = new StatFs(path.getPath());
       long blockSize = stat.getBlockSize();
       long availableBlocks = stat.getAvailableBlocks();
       return Formatter.formatFileSize(SimpleActivity.this, blockSize * availableBlocks);
   }
 
Example 32
Project: stynico   File: FxService.java   Source Code and License 5 votes vote down vote up
private String getRomAvailableSize()
{
    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long availableBlocks = stat.getAvailableBlocks();
    return Formatter.formatFileSize(this, blockSize * availableBlocks);
}
 
Example 33
Project: FastDownloader   File: DownloadViewHolder.java   Source Code and License 5 votes vote down vote up
@Override
public void setData(DownLoadInfo data) {
    this.data = data;
    checkTypeUI(data);
    mProgress.setMax((int) data.mTotalbytes);
    mProgress.setProgress((int) data.mDownloadedbytes);
    mSpeed.setText(Formatter.formatFileSize(mContext, data.mSpeed) + "/s");
    mPercent.setText(data.mFilename);
    mSize.setText(Utils.formatFilesize(data.mDownloadedbytes) + "/" );
    mFlieSize.setText(Utils.formatFilesize(data.mTotalbytes));
    checkUI(data);
}
 
Example 34
Project: stynico   File: MainActivity.java   Source Code and License 5 votes vote down vote up
private void getCaches(){
    // scan
    pm = getPackageManager();
    List<PackageInfo> packages = pm.getInstalledPackages(0);

    int max = packages.size();
    int current = 0;
    sb.delete(0, sb.length());
    sb.append("");
    sb.append("本机一共安装了:" + max+"个应用");
    tvShowCaches.setText(sb.toString());
    for (PackageInfo pinfo : packages) {
        String packageName = pinfo.packageName;
        try {

            Method getPackageSizeInfo = PackageManager.class
                    .getDeclaredMethod("getPackageSizeInfo", String.class, IPackageStatsObserver.class);
            getPackageSizeInfo.invoke(pm, packageName, new MyPackageStateObserver());
            current++;
        } catch (Exception e) {
            current++;
            e.printStackTrace();
        }

    }
    //===到这里,数据准备完成
    mHadler.postDelayed(new Runnable() {
        @Override
        public void run() {
btnClearAll.setVisibility(View.VISIBLE);
            Toast.makeText(getApplicationContext(),"已读取全部缓存",Toast.LENGTH_SHORT).show();
            sbCache.append(Formatter.formatFileSize(getApplicationContext(),cacheS)+"\n");
            tvShowCaches.setText(sb.toString());
            tvAppCache.setText(sbCache.toString());
            sbCache.delete(0,sbCache.length());
        }
    }, 1000);
    //ok,所有应用程序信息显示完成
}
 
Example 35
Project: Bailan   File: AppIntroduceFragment.java   Source Code and License 5 votes vote down vote up
@Override
protected View cretaeSuccessView() {
    View view = UIUtils.inflate(R.layout.fragment_app_introduction);
    ButterKnife.bind(this, view);

    /*应用截图数据*/
    for (int i = 0; i < mIntroductionBean.getImageCompressList().size(); i++) {
        String url = mIntroductionBean.getImageCompressList().get(i);
        View screenView = View.inflate(getContext(), R.layout.appdetail_item_screen_image, null);
        ImageView screenImageView = (ImageView) screenView.findViewById(R.id.appdetail_screen_img_imageview);
        //设置图片描述(一般用户是看不到的)
        screenImageView.setContentDescription(screenImageView.getResources().getString(R.string.appdetail_screenshot));
        //设置图片的放大模式
        screenImageView.setScaleType(ImageView.ScaleType.FIT_XY);
        screenView.setOnClickListener(this);
        screenView.setTag(i);
        Glide.with(UIUtils.getContext()).load(url).into(screenImageView);
        app_detail_gallery_container.addView(screenView);
    }

    /*应用信息描述*/
    appInfoTariff.setText(mIntroductionBean.getAppInfoBean().getTariffDesc());
    appInfoSize.setText(Formatter.formatFileSize(getContext(), Long.parseLong(mIntroductionBean.getAppInfoBean().getSize())));
    appInfoDate.setText(mIntroductionBean.getAppInfoBean().getReleaseDate());
    appInfoVersion.setText(mIntroductionBean.getAppInfoBean().getVersion());
    appInfoDeveloper.setText(mIntroductionBean.getAppInfoBean().getDeveloper());

    for (int i = 0; i < mIntroductionBean.getAppDetailInfoBeanList().size(); i++) {
        FoldingTextView foldingTextView = new FoldingTextView(getContext());
        foldingTextView.setTitle(mIntroductionBean.getAppDetailInfoBeanList().get(i).getTitle());
        foldingTextView.setContent(mIntroductionBean.getAppDetailInfoBeanList().get(i).getBody());
        appInfoDes.addView(foldingTextView);
    }

    //应用标签数据
    List<String> tagList = mIntroductionBean.getTagList();
    for (int i = 0; i < tagList.size(); i++) {
        View labView = UIUtils.inflate(R.layout.appdetail_item_label_item);
        TextView tv = (TextView) labView.findViewById(R.id.appdetail_label_content_textview);
        tv.setText(tagList.get(i));
        flowLayout.addView(labView);
    }

    return view;
}
 
Example 36
Project: SDCardCleaner   File: FileListAdapter.java   Source Code and License 5 votes vote down vote up
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    SDFile _temp_data = _data.get_children().get(position);
    //设置文件大小比例条
    float _percent = (float) NumberUtil.div(_temp_data.get_sizePercent(), 100, 2);
    PercentRelativeLayout.LayoutParams _params = new PercentRelativeLayout.LayoutParams(0, 0);
    _params.getPercentLayoutInfo().widthPercent = _percent;
    holder._view_percent.setLayoutParams(_params);
    int _color = (int) _evaluator.evaluate(_percent, COLOR_START, COLOR_END);
    holder._view_percent.setBackgroundColor(_color);
    //设置清理标志
    if (_temp_data.isRubbish())
        holder._image_rubbish.setVisibility(ImageView.VISIBLE);
    else
        holder._image_rubbish.setVisibility(ImageView.GONE);
    //设置类型图标
    if (_temp_data.isDirectory())
        holder._image_type.setImageResource(R.drawable.icon_directory);
    else
        holder._image_type.setImageResource(R.drawable.icon_file);
    //设置基本信息
    holder._text_name.setText(_temp_data.get_name());
    String _str_size;
    if (_temp_data.isDirectory())
        _str_size = holder._view_click.getContext().getString(R.string.state_directory_size, Formatter.formatFileSize(holder._view_click.getContext(), _temp_data.get_size()), _temp_data.get_fileCount());
    else
        _str_size = Formatter.formatFileSize(holder._view_click.getContext(), _temp_data.get_size());
    holder._text_size.setText(_str_size);
    holder._view_click.setTag(new String[]{ACTION_CLICK_ITEM, String.valueOf(position)});
}
 
Example 37
Project: easyfilemanager   File: DetailFragment.java   Source Code and License 5 votes vote down vote up
@Override
protected Void doInBackground(Void... params) {
	filePath = doc.path;

	if (!Utils.isDir(doc.mimeType)) {
              final boolean allowThumbnail = MimePredicate.mimeMatches(MimePredicate.VISUAL_MIMES, doc.mimeType);
		int thumbSize = getResources().getDimensionPixelSize(R.dimen.grid_width);
		Point mThumbSize = new Point(thumbSize, thumbSize);
		final Uri uri = DocumentsContract.buildDocumentUri(doc.authority, doc.documentId);
		final Context context = getActivity();
		final ContentResolver resolver = context.getContentResolver();
		ContentProviderClient client = null;
		try {

			if (doc.mimeType.equals(Document.MIME_TYPE_APK) && !TextUtils.isEmpty(filePath)) {
				result = ((BitmapDrawable) IconUtils.loadPackagePathIcon(context, filePath, Document.MIME_TYPE_APK)).getBitmap();
			} else {
				client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, uri.getAuthority());
				result = DocumentsContract.getDocumentThumbnail(resolver, uri, mThumbSize, null);
			}
		} catch (Exception e) {
			if (!(e instanceof OperationCanceledException)) {
				Log.w(TAG_DETAIL, "Failed to load thumbnail for " + uri + ": " + e);
			}
			CrashReportingManager.logException(e);
		} finally {
			ContentProviderClientCompat.releaseQuietly(client);
		}

		sizeString = Formatter.formatFileSize(context, doc.size);
	}
	else{
		if(!TextUtils.isEmpty(filePath)){
			File dir = new File(filePath);
			sizeString = Formatter.formatFileSize(getActivity(), Utils.getDirectorySize(dir));
		}				
	}
	
	return null;
}
 
Example 38
Project: easyfilemanager   File: DirectoryFragment.java   Source Code and License 5 votes vote down vote up
@Override
protected void onPostExecute(Long result) {
          if (isCancelled()) {
              result = null;
          }
	if (mSizeView.getTag() == this && result != null) {
		mSizeView.setTag(null);
		String size = Formatter.formatFileSize(mSizeView.getContext(), result);
		mSizeView.setText(size);
		mSizes.put(mPosition, result);
	}
}
 
Example 39
Project: easyfilemanager   File: HomeItem.java   Source Code and License 5 votes vote down vote up
public void setInfo(RootInfo root) {

        icon.setImageDrawable(root.loadDrawerIcon(mContext));
        title.setText(root.title);

        // Show available space if no summary
        String summaryText = root.summary;
        if (TextUtils.isEmpty(summaryText) && root.availableBytes >= 0) {
            summaryText = mContext.getString(R.string.root_available_bytes,
                    Formatter.formatFileSize(mContext, root.availableBytes));
            try {
                Long current = 100 * root.availableBytes / root.totalBytes ;
                progress.setVisibility(View.VISIBLE);
                progress.setMax(100);
                progress.setProgress(100 - current.intValue());
                progress.setColor(color);
            }
            catch (Exception e){
                progress.setVisibility(View.GONE);
            }
        }
        else{
            progress.setVisibility(View.GONE);
        }

        summary.setText(summaryText);
        summary.setVisibility(TextUtils.isEmpty(summaryText) ? View.GONE : View.VISIBLE);
    }
 
Example 40
Project: AndroidBasicLibs   File: MemoryUtil.java   Source Code and License 5 votes vote down vote up
/**
 * Get available memory
 *
 * @param context
 * @return
 */
public static String getAvailableMemory(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
    am.getMemoryInfo(mi);
    return Formatter.formatFileSize(context, mi.availMem);
}
 
Example 41
Project: AndroidBasicLibs   File: MemoryUtil.java   Source Code and License 5 votes vote down vote up
/**
 * Get all memory
 *
 * @param context
 * @return
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static String getAllMemory(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
    am.getMemoryInfo(mi);
    return Formatter.formatFileSize(context, mi.totalMem);
}
 
Example 42
Project: AndroidBasicLibs   File: MemoryCache.java   Source Code and License 5 votes vote down vote up
/**
 * Get available memory
 *
 * @param context
 * @return
 */
public static String getAvailableMemory(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
    am.getMemoryInfo(mi);
    return Formatter.formatFileSize(context, mi.availMem);
}
 
Example 43
Project: AndroidBasicLibs   File: MemoryUtil.java   Source Code and License 5 votes vote down vote up
/**
 * Get available memory info.
 */
@TargetApi(Build.VERSION_CODES.CUPCAKE)
public static String getAvailMemory(Context context) {// 获取android当前可用内存大小
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
    am.getMemoryInfo(mi);
    // mi.availMem; 当前系统的可用内存
    return Formatter.formatFileSize(context, mi.availMem);// 将获取的内存大小规格化
}
 
Example 44
Project: Auto.js   File: WifiTool.java   Source Code and License 5 votes vote down vote up
public static String getRouterIp(Context context){
    WifiManager wifiService = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    if(wifiService == null){
        return null;
    }
    DhcpInfo dhcpInfo = wifiService.getDhcpInfo();
    return Formatter.formatIpAddress(dhcpInfo.gateway);
}
 
Example 45
Project: treasure   File: MemoryUtil.java   Source Code and License 5 votes vote down vote up
/**
 * Get available memory info.
 */
@TargetApi(Build.VERSION_CODES.CUPCAKE)
public static String getAvailMemory(Context context) {// 获取android当前可用内存大小
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
    am.getMemoryInfo(mi);
    // mi.availMem; 当前系统的可用内存
    return Formatter.formatFileSize(context, mi.availMem);// 将获取的内存大小规格化
}
 
Example 46
Project: XinFramework   File: MemoryUtil.java   Source Code and License 5 votes vote down vote up
/**
 * Get available memory info.
 */
@TargetApi(Build.VERSION_CODES.CUPCAKE)
public static String getAvailMemory(Context context) {// 获取android当前可用内存大小
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
    am.getMemoryInfo(mi);
    // mi.availMem; 当前系统的可用内存
    return Formatter.formatFileSize(context, mi.availMem);// 将获取的内存大小规格化
}
 
Example 47
Project: chromium-for-android-56-debug-video   File: WebsitePreference.java   Source Code and License 5 votes vote down vote up
@Override
protected void onBindView(View view) {
    super.onBindView(view);

    TextView usageText = (TextView) view.findViewById(R.id.usage_text);
    usageText.setVisibility(View.GONE);
    if (mCategory.showStorageSites()) {
        long totalUsage = mSite.getTotalUsage();
        if (totalUsage > 0) {
            usageText.setText(Formatter.formatShortFileSize(getContext(), totalUsage));
            usageText.setTextSize(TEXT_SIZE_SP);
            usageText.setVisibility(View.VISIBLE);
        }
    }

    if (!mFaviconFetched) {
        // Start the favicon fetching. Will respond in onFaviconAvailable.
        mFaviconHelper = new FaviconHelper();
        if (!mFaviconHelper.getLocalFaviconImageForURL(
                    Profile.getLastUsedProfile(), faviconUrl(), mFaviconSizePx, this)) {
            onFaviconAvailable(null, null);
        }
        mFaviconFetched = true;
    }

    float density = getContext().getResources().getDisplayMetrics().density;
    int iconPadding = Math.round(FAVICON_PADDING_DP * density);
    View iconView = view.findViewById(android.R.id.icon);
    iconView.setPadding(iconPadding, iconPadding, iconPadding, iconPadding);
}
 
Example 48
Project: chromium-for-android-56-debug-video   File: SingleCategoryPreferences.java   Source Code and License 5 votes vote down vote up
/** OnClickListener for the clear button. We show an alert dialog to confirm the action */
@Override
public void onClick(View v) {
    if (getActivity() == null || v != mClearButton) return;

    long totalUsage = 0;
    if (mWebsites != null) {
        for (WebsitePreference preference : mWebsites) {
            totalUsage += preference.site().getTotalUsage();
        }
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setPositiveButton(R.string.storage_clear_dialog_clear_storage_option,
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    clearStorage();
                }
            });
    builder.setNegativeButton(R.string.cancel, null);
    builder.setTitle(R.string.storage_clear_site_storage_title);
    Resources res = getResources();
    String dialogFormattedText = res.getString(R.string.storage_clear_dialog_text,
            Formatter.formatShortFileSize(getActivity(), totalUsage));
    builder.setMessage(dialogFormattedText);
    builder.create().show();
}
 
Example 49
Project: letv   File: DownloadService.java   Source Code and License 5 votes vote down vote up
public void calculateDownloadSpeed(long lastStarted, long curtime, long downloadedSize) {
    long time = (curtime - lastStarted) / 1000;
    if (time > 0) {
        this.mSpeed = Formatter.formatFileSize(mContext, downloadedSize / time) + "/s";
        return;
    }
    this.mSpeed = "0.00 B/s";
}
 
Example 50
Project: letv   File: FileDownloader.java   Source Code and License 5 votes vote down vote up
public String calculateDownloadSpeed(long timestamp, long curtime, long downloadedSize) {
    long time = (curtime - timestamp) / 1000;
    if (time <= 0 || downloadedSize <= 0) {
        return "";
    }
    return Formatter.formatFileSize(this.mContext, downloadedSize / time) + "/s";
}
 
Example 51
Project: letv   File: DownloadUtil.java   Source Code and License 5 votes vote down vote up
public static String calculateDownloadSpeed(long timestamp, long curtime, long downloadedSize) {
    long time = (curtime - timestamp) / 1000;
    if (time <= 0 || downloadedSize <= 0) {
        return "";
    }
    return Formatter.formatFileSize(BaseApplication.getInstance(), downloadedSize / time) + "/s";
}
 
Example 52
Project: letv   File: WorldCupDownloadManager.java   Source Code and License 5 votes vote down vote up
public void completeDownloadInfo(String id) {
    DownloadInfo info = (DownloadInfo) this.downloadMaps.get(id);
    Constants.debug("finishDownload:" + info.id + SearchCriteria.LT + info.isHd + ">:" + Formatter.formatFileSize(this.mContext, info.total));
    synchronized (this.downloadMaps) {
        this.downloadMaps.remove(id);
    }
    NotifyManage.notifyFinish(this.mContext, info);
    startPendingDownload();
}
 
Example 53
Project: letv   File: WorldCupDownloadManager.java   Source Code and License 5 votes vote down vote up
public void calculateDownloadSpeed(long lastStarted, long curtime, long downloadedSize) {
    long time = (curtime - lastStarted) / 1000;
    if (time > 0) {
        this.speed = new StringBuilder(String.valueOf(Formatter.formatFileSize(this.mContext, downloadedSize / time))).append("/s").toString();
        return;
    }
    this.speed = "0.00 B/s";
}
 
Example 54
Project: letv   File: NetworkUtils.java   Source Code and License 5 votes vote down vote up
public static String getGatewayIP(Context context) {
    try {
        return Formatter.formatIpAddress(((WifiManager) context.getSystemService(NETWORK_NAME_WIFI)).getDhcpInfo().gateway);
    } catch (Throwable e) {
        LogTool.e(TAG, "", e);
        return "";
    }
}
 
Example 55
Project: buildAPKsApps   File: MainSettingsActivity.java   Source Code and License 5 votes vote down vote up
private String getMemoryStatus(File path, int resId) {
	try {
           StatFs stat = new StatFs(path.getPath());
           long blockSize = stat.getBlockSize();
           long totalBlocks = stat.getBlockCount();
           long availableBlocks = stat.getAvailableBlocks();
           
           if (DEBUG) {
           	Log.d(TAG, "memory/path: " + path + " ------------");
           	Log.d(TAG, "memory/blockSize: " + blockSize);
           	Log.d(TAG, "memory/totalBlocks: " + totalBlocks);
           	Log.d(TAG, "memory/availableBlocks: " + availableBlocks);
           }

           long totalSize = totalBlocks * blockSize;
           long availableSize = availableBlocks * blockSize;
           long availablePercent = (totalSize == 0) ? -1 : availableSize * 100 / totalSize;
           
           if (Constants.DEBUG) {
           	Log.d(TAG, "memory/totalSize: " + totalSize);
           	Log.d(TAG, "memory/availableSize: " + availableSize);
           }
           
           String res = getString(resId);
           if (availablePercent > -1) {
           	res += " (" + availablePercent + "%)";
           } else {
           }
           res += " " + Formatter.formatFileSize(this, availableSize);
           return res;
           
       } catch (IllegalArgumentException e) {
           // this can occur if the SD card is removed, but we haven't received the 
           // ACTION_MEDIA_REMOVED Intent yet.
           return null;
       }		
}
 
Example 56
Project: jackknife   File: IoUtils.java   Source Code and License 5 votes vote down vote up
public static String getRomTotalSize(Context context) {
    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long totalBlocks = stat.getBlockCount();
    return Formatter.formatFileSize(context, blockSize * totalBlocks);
}
 
Example 57
Project: aos-Video   File: VideoInfoActivityFragment.java   Source Code and License 5 votes vote down vote up
private void  setFileInfo(VideoMetadata videoMetadata){
    // Special error case (99.9% of the time it happens when the specified file is not reachable)
    if (videoMetadata.getFileSize()==0 && videoMetadata.getVideoTrack()==null && videoMetadata.getAudioTrackNb()==0) {
        mFileError.setVisibility(View.VISIBLE);
        mFileInfoContainerLoading.setVisibility(View.GONE);
        mFileInfoAudioVideoContainer.setVisibility(View.GONE);
        mDuration.setVisibility(View.GONE);
        mFileSize.setVisibility(View.GONE);
    }
    else {
        mFileError.setVisibility(View.GONE);
        if (videoMetadata.getVideoTrack() != null) {
            mVideoTrackTextView.setText(VideoInfoCommonClass.getVideoTrackString(videoMetadata, getResources()));
        }
        mFileInfoAudioVideoContainer.setVisibility(View.VISIBLE);
        mFileInfoContainerLoading.setVisibility(View.GONE);
        mDuration.setVisibility(View.VISIBLE);
        mFileSize.setVisibility(View.VISIBLE);
        mFileSize.setText(Formatter.formatFileSize(getActivity(), videoMetadata.getFileSize()));
        mDuration.setText(Browser.formatTime(videoMetadata.getDuration()));
        String decoder = VideoInfoCommonClass.getDecoder(videoMetadata, getResources(), mPlayerType);
        setTextOrHideContainer(mDecoderTextView, decoder, mDecoderTextView);
        String audiotrack = VideoInfoCommonClass.getAudioTrackString(videoMetadata, getResources(), getActivity());
        setTextOrHideContainer(mAudioTrackTextView, audiotrack, mRoot.findViewById(R.id.audio_row));
    }

}
 
Example 58
Project: phonk   File: NetworkUtils.java   Source Code and License 5 votes vote down vote up
public static void getGatewayIpAddress(Context c) {
    // get wifi ip

    final WifiManager manager = (WifiManager) c.getSystemService(Context.WIFI_SERVICE);
    final DhcpInfo dhcp = manager.getDhcpInfo();
    final String address = Formatter.formatIpAddress(dhcp.gateway);

    StringBuilder IFCONFIG = new StringBuilder();
    try {
        for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) {
            NetworkInterface intf = en.nextElement();
            for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
                InetAddress inetAddress = enumIpAddr.nextElement();
                if (!inetAddress.isLoopbackAddress() && !inetAddress.isLinkLocalAddress()
                        && inetAddress.isSiteLocalAddress()) {
                    IFCONFIG.append(inetAddress.getHostAddress().toString() + "\n");
                }

            }
        }
    } catch (SocketException ex) {
        Log.e("LOG_TAG", ex.toString());
    }
    MLog.d(TAG, "ifconfig " + IFCONFIG.toString());

    MLog.d(TAG, "hotspot address is " + address);

}
 
Example 59
Project: PrismatikRemote   File: NetworkHelper.java   Source Code and License 5 votes vote down vote up
public static String getNetPartOfIpAddress(Context context) {
    WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    wm.getConnectionInfo().getNetworkId();
    String ip = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());
    ip = ip.substring(0, ip.lastIndexOf('.')+1);
    return ip;
    // TODO: get subnetmask and build net address
}
 
Example 60
Project: ZhidaoDaily-android   File: DataCleanManager.java   Source Code and License 5 votes vote down vote up
/**
 * 获取缓存大小
 *
 * @param context context
 * @return 0KB/23MB
 */
public static String getCacheSize(Context context) {
    File cache = context.getCacheDir();
    File exCache = context.getExternalCacheDir();
    long size = getFolderSize(cache) + getFolderSize(exCache);
    return Formatter.formatFileSize(context, size);
}