今、このコードの約 6 ~ 7 のバリエーションを試しましたが、何かが正しくありません。私はほとんど同じコードを持っています (ondraw の部分だけが少し異なり、指の入力をキャッチする準備ができています) が動作します。しかし、ここでは黒で描画します。時計に似たタイマーを作成する必要があります。だから私は赤で円を描き、経過時間に応じて、その円の上に PorterDuff.Mode.CLEAR で描画して削除します。現在、私は通常これを行いませんが、私はちょっと必死で、すぐに答えが必要なので、クラスからすべてのコードを投稿します。アクティビティまたはビューのどこにでもある可能性があります:
これは、相対レイアウトに追加するために作成したカスタム ビューです。
public TimeView(Context mContext, Bitmap bitmapgol, Canvas canvas) {
super(mContext);
context = mContext;
this.canvas = canvas;
displayWidth = getResources().getDisplayMetrics().widthPixels;
displayHeight = getResources().getDisplayMetrics().heightPixels;
try {
setBitmap(bitmapgol, bitmapgol.getConfig());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
density = getResources().getDisplayMetrics().density;
mBitmapPaint = new Paint(Paint.DITHER_FLAG);
LogService.log("", "density" + density + " | W: " + displayWidth + " | H : " + displayHeight);
float middle = displayWidth / 2;
rectF = new RectF(middle / 2 - 32 * density, middle / 2 - 52 * density, middle + middle / 2 + 32 * density, middle + middle / 2 + 12 * density);
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setAntiAlias(true);
paint.setDither(true);
paint.setColor(Color.TRANSPARENT);
paint.setAlpha(0);
paint.setXfermode(pd);
}
protected void onDraw(Canvas canvas) {
// super.onDraw(canvas);
if (bitmap != null) {
canvas.drawBitmap(this.bitmap, 0, 0, mBitmapPaint);
} else {
LogService.log("", "NULLLLLLLL");
}
paint.setColor(getResources().getColor(R.color.timer_clock));
paint.setAlpha(255);
paint.setStrokeWidth(2.0f);
int circleRadius = (int) (110 * density);
paint.setStyle(Paint.Style.FILL);
canvas.drawCircle(rectF.centerX(), rectF.centerY(), circleRadius, paint);
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.TRANSPARENT);
paint.setAlpha(0);
paint.setXfermode(pd);
canvas.drawArc(rectF, -90, 360 - percent, true, paint);
paint.setStyle(Paint.Style.STROKE);
paint.setColor(Color.BLACK);
paint.setXfermode(null);
paint.setAlpha(255);
paint.setStyle(Paint.Style.FILL);
paint.setTextSize(25 * density);
if (time != -1) {
paint.setColor(Color.BLACK);
if (red) {
paint.setColor(Color.RED);
}
int hours = (int) (time / (60 * 60 * 1000));
int hoursMod = (int) (time % (60 * 60 * 1000));
int min = (int) (hoursMod / (1000 * 60));
int minMod = (int) (hoursMod % (1000 * 60));
int seconds = (int) (minMod / 1000);
if (hours != 0) {
String timeS = hours + "h " + min + "m " + seconds + "s ";
drawDigit(canvas, (int) (25 * density), rectF.centerX(), rectF.centerY(), paint.getColor(), timeS);
} else if (min != 0) {
String timeS = min + "m " + seconds + "s ";
drawDigit(canvas, (int) (25 * density), rectF.centerX(), rectF.centerY(), paint.getColor(), timeS);
} else {
String timeS = seconds + "s ";
drawDigit(canvas, (int) (25 * density), rectF.centerX(), rectF.centerY(), paint.getColor(), timeS);
}
} else {
paint.setColor(Color.RED);
String timeS = "Finished";
drawDigit(canvas, (int) (25 * density), rectF.centerX(), rectF.centerY(), paint.getColor(), timeS);
}
invalidate();
}
public void setTime(long millisUntilFinished) {
percent = millisUntilFinished * ratio;
invalidate();
}
public void setFullTime(int timeToCount) {
ratio = (float) (360f / timeToCount);
}
public void setTimeForText(long time, boolean red) {
this.time = time;
this.red = red;
}
private void drawDigit(Canvas canvas, int textSize, float cX, float cY, int color, String text) {
Paint tempTextPaint = new Paint();
tempTextPaint.setAntiAlias(true);
tempTextPaint.setStyle(Paint.Style.FILL);
tempTextPaint.setColor(color);
tempTextPaint.setTextSize(textSize);
float textWidth = tempTextPaint.measureText(text);
canvas.drawText(text, cX - (textWidth / 2), cY + (textSize / 2), tempTextPaint);
}
@SuppressLint("NewApi")
public void setBitmap(Bitmap bitmap, Bitmap.Config targetConfig) throws Exception { // se cheama in Paint Activity sa se seteze bitmapu
LogService.log("", "bitmap1 : " + bitmap);
File file = new File(Environment.getExternalStorageDirectory() + "/sample/temp.txt");
file.getParentFile().mkdirs();
file.setWritable(true);
file.setReadable(true);
file.setExecutable(true);
randomAccessFile = new RandomAccessFile(file, "rw");
int bWidth = bitmap.getWidth();
int bHeight = bitmap.getHeight();
FileChannel channel = randomAccessFile.getChannel();
MappedByteBuffer map = channel.map(MapMode.READ_WRITE, 0, bWidth * bHeight * 4);
bitmap.copyPixelsToBuffer(map);
bitmap.recycle();
this.bitmap = Bitmap.createBitmap(bWidth, bHeight, targetConfig);
map.position(0);
this.bitmap.copyPixelsFromBuffer(map);
channel.close();
randomAccessFile.close();
LogService.log("", "bitmap1 : " + this.bitmap);
}
これは、TimeView を追加するアクティビティです。
public class ActivityRemainingTime extends Activity implements OnClickListener {
private final static String TAG = ActivityRemainingTime.class.getSimpleName();
TimeView timeview;
CountDownTimer count;
int reminder;// va fi ales
RelativeLayout timeExtend;
AlarmManager alarmManager;
AlarmReceiver alarmReceiver;
int timeToCount = 1;
private PendingIntent pendingIntent;
private Timer t;
RelativeLayout timeV;
OnValueChangeListener valuechangedListener;
int timeAdded = 0;
NumberPicker hoursNP, minutesNP;
Bundle b;
private Bitmap bitmapgol;
private int hourOfDay;
private ArrayList<Taxes> taxes = new ArrayList<Taxes>();
private RelativeLayout loader;
private long millistofinish = 0;
// Define the listener for the slide in/out animations
private Animation.AnimationListener animListener = new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
// Get the text off the "new parking" text view
String newParkingText = ((TextView) findViewById(R.id.time_new_parking_tv)).getText().toString();
// Check to see whether the the animation was a slide in or slide out
if (newParkingText.contentEquals(getString(R.string.time_new_parking))) {
// It was a slide OUT
// Show the remaining time TV
} else {
// It was a slide IN
// Instantiate the intent and attach the required values to it
Intent intent = new Intent(ActivityRemainingTime.this, ActivityPayment.class);
intent.putExtra("extended", true);
intent.putExtra("timeAdded", timeAdded);
startActivityForResult(intent, Constants.ACTIVITY_PAYMENT);
LogService.log(TAG, "timeadded is when entering: " + timeAdded);
if (alarmManager != null) {
alarmManager.cancel(pendingIntent);
}
}
}
};
private RandomAccessFile randomAccessFile;
private int displayWidth;
private int displayHeight;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_remaining_time);
LogService.log(TAG, "onCreate");
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("intent_myaction_alarm");
displayWidth = getResources().getDisplayMetrics().widthPixels;
displayHeight = getResources().getDisplayMetrics().heightPixels;
// Set the on click listeners for the buttons
((RelativeLayout) findViewById(R.id.time_new_parking)).setOnClickListener(this);
((RelativeLayout) findViewById(R.id.time_extend_time)).setOnClickListener(this);
loader = (RelativeLayout) findViewById(R.id.splash_screen_loader_container);
// Initialize the title bar
TitleBarHandler.initTitleBar(this, "Munsterlingen|Switzerland", false, true);
WSCalls.webserviceCallParkingCharges(loader, ActivityRemainingTime.this, new GetBackFromWS() {
@Override
public void success() {
}
@Override
public void success(ArrayList<Taxes> taxes) {
if (ActivityRemainingTime.this.taxes != null) {
ActivityRemainingTime.this.taxes.clear();
}
for (int i = 0; i < taxes.size(); i++) {
Taxes tax = new Taxes(taxes.get(i).getPrice(), taxes.get(i).getMinutes() - (Constants.timeToCount / 60));
ActivityRemainingTime.this.taxes.add(tax);
}
}
});
/*
* Configure the number pickers and at the same time disable the softkeyboard on them
*/
// Get number picker references
hoursNP = (NumberPicker) findViewById(R.id.select_hour_number_picker);
minutesNP = (NumberPicker) findViewById(R.id.select_min_number_picker);
// Initialize pickers with values
Tools.initializeNumberPicker(hoursNP, 0, 14, 1);
Tools.initializeNumberPicker(minutesNP, 0, 59, 1);
// Disable softkeyboard
// hoursNP.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
// minutesNP.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
timeV = (RelativeLayout) findViewById(R.id.timeViewLayout);
valuechangedListener = new OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
calculateTime();
}
};
hoursNP.setOnValueChangedListener(valuechangedListener);
minutesNP.setOnValueChangedListener(valuechangedListener);
EditText hoursInput = Tools.findInput(hoursNP);
EditText minutesInput = Tools.findInput(minutesNP);
hoursInput.setInputType(InputType.TYPE_CLASS_NUMBER);
minutesInput.setInputType(InputType.TYPE_CLASS_NUMBER);
b = this.getIntent().getExtras();
if (b != null) {
timeToCount = b.getInt("timeToCount", 0);
reminder = b.getInt("reminder", 600);
LogService.log(TAG, "hei time to count: " + Constants.timeToCount + " |new time to count| " + timeToCount);
if (timeToCount != 0) {
Constants.timeToCount = timeToCount;
PersistentUtil.setTimeToCount(ActivityRemainingTime.this, timeToCount);
} else if (timeToCount == 0) {
timeToCount = Constants.timeToCount;
}
LogService.log(TAG, "bundle NOT null: " + reminder + " || " + Constants.timeToCount);
b = null;
} else {
LogService.log(TAG, "bundle null");
}
LogService.log(TAG, "Spotname: " + PersistentUtil.getSelectedSpot(ActivityRemainingTime.this));
initTimeView();
}
@Override
protected void onPause() {
LogService.log(TAG, "onPause");
if (count != null) {
count.cancel();
}
super.onPause();
}
@Override
protected void onResume() {
super.onResume();
LogService.log(TAG, "onResume");
if (b == null) {
LogService.log(TAG, "resume bundle null");
Constants.timeToCount = PersistentUtil.getTimeToCount(ActivityRemainingTime.this);
Constants.exactTime = PersistentUtil.getExactTime(ActivityRemainingTime.this);
timeview.setFullTime(Constants.timeToCount);
}
/*
* Reset the footer to go back to default states
*/
// Set the text of the
((TextView) findViewById(R.id.time_new_parking_tv)).setText(getString(R.string.time_new_parking));
// Show the time displayed above the footer
// Reset the number pickers to zero
hoursNP.setValue(0);
minutesNP.setValue(0);
/*
* Reinitialize the reminder value
*/
// Get the index of the beed which was selected -1 or in interval [1, 5]
int selectedIndex = PersistentUtil.getSelectedBeed(this);
// Get the time of the beed
reminder = Tools.getSeconds(0, Integer.parseInt(ActivityMain.getTimeFromBeedIndex(selectedIndex)));
// Re-initialize the timer view
LogService.log(TAG, "on resume Time to count: " + ((System.currentTimeMillis() - Constants.exactTime) - (((Constants.timeToCount * 1000) - (reminder * 1000)))));
if ((System.currentTimeMillis() - Constants.exactTime) < ((Constants.timeToCount * 1000) - (reminder * 1000))) {
initAlarmReceiver((Constants.timeToCount * 1000) - (reminder * 1000));
}
if (System.currentTimeMillis() - Constants.exactTime > 1000) {
final float begin = (System.currentTimeMillis() - PersistentUtil.getExactTime(ActivityRemainingTime.this));
LogService.log(TAG, "Time EXACT starting time: " + PersistentUtil.getExactTime(ActivityRemainingTime.this));
LogService.log(TAG, "Time: " + begin);
LogService.log(TAG, "TimeToCount: " + Constants.timeToCount * 1000);
if (begin < (PersistentUtil.getTimeToCount(ActivityRemainingTime.this) * 1000)) {
LogService.log(TAG, "Countdown timer: " + ((Constants.timeToCount * 1000) - begin));
timeToCount((int) ((Constants.timeToCount * 1000) - begin));
} else {
LogService.log(TAG, "Timer initiated in ELSE");
t = new Timer();
t.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
public void run() {
if (timeview == null) {
bitmapgol = Bitmap.createBitmap(displayWidth, displayHeight, Config.ARGB_8888);
Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.background);
try {
Bitmap bit = setMuttable(icon);
Canvas canvas = new Canvas(bit);
timeview = new TimeView(ActivityRemainingTime.this, bitmapgol, canvas);
tryPorterDuff();
timeV.addView(timeview);
timeview.setFullTime(Constants.timeToCount);
timeV.bringToFront();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
timeview.setTime(0);
timeview.setTimeForText(-1, true);
final float begin = (System.currentTimeMillis() - Constants.exactTime);
int millisUntilFinished = (int) -((Constants.timeToCount * 1000) - begin);
LogService.log(TAG, "intrat la millisUntilFinished" + millisUntilFinished);
if (millisUntilFinished < 2100000000) {
timeview.setTimeForText(millisUntilFinished, true);
} else {
LogService.log(TAG, "intrat in else la timertask");
Constants.timeToCount = -1;
Constants.exactTime = -1;
PersistentUtil.setTimeToCount(ActivityRemainingTime.this, Constants.timeToCount);
PersistentUtil.setExactTime(ActivityRemainingTime.this, Constants.exactTime);
}
}
});
}
}, 0, 1000);
}
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK)) {
Tools.showCloseAppConfirmation(this);
}
return super.onKeyDown(keyCode, event);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case Constants.ACTIVITY_PAYMENT:
if (resultCode == Constants.CLOSE_ACTIVITY)
finish();
break;
}
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.time_new_parking:
if (((TextView) findViewById(R.id.time_new_parking_tv)).getText().toString().contentEquals(getString(R.string.time_new_parking_save))) {
if (inputDataIsValid()) {
collapse((RelativeLayout) findViewById(R.id.footer_extend_slider));
}
} else {
PersistentUtil.setTimerStarted(this, false);
startActivity(new Intent(this, ActivityMain.class));
if (alarmManager != null) {
alarmManager.cancel(pendingIntent);
}
finish();
}
break;
case R.id.time_extend_time:
if (((TextView) findViewById(R.id.time_new_parking_tv)).getText().toString().contentEquals(getString(R.string.time_new_parking_save))) {
((ImageView) findViewById(R.id.extend_arrow)).setImageResource(R.drawable.disclosure_arrow);
((TextView) findViewById(R.id.time_new_parking_tv)).setText(getString(R.string.time_new_parking));
collapse((RelativeLayout) findViewById(R.id.footer_extend_slider));
} else {
((ImageView) findViewById(R.id.extend_arrow)).setImageResource(R.drawable.disclosure_arrow_down);
((TextView) findViewById(R.id.time_new_parking_tv)).setText(getString(R.string.time_new_parking_save));
expand((RelativeLayout) findViewById(R.id.footer_extend_slider));
}
break;
}
}
private void timeToCount(int timec) {
count = new CountDownTimer(timec, 1000) {
public void onTick(long millisUntilFinished) {
millistofinish = millisUntilFinished;
if (timeview == null) {
bitmapgol = Bitmap.createBitmap(displayWidth, displayHeight, Config.ARGB_8888);
Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.background);
try {
Bitmap bit = setMuttable(icon);
Canvas canvas = new Canvas(bit);
timeview = new TimeView(ActivityRemainingTime.this, bitmapgol, canvas);
tryPorterDuff();
timeV.addView(timeview);
timeview.setFullTime(Constants.timeToCount);
timeV.bringToFront();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
timeview.setTime(millisUntilFinished / 1000);
timeview.setTimeForText(millisUntilFinished, false);
}
public void onFinish() {
timeview.setTimeForText(-1, true);
timeview.setTime(0);
LogService.log(TAG, "Alarma: " + System.currentTimeMillis());
millistofinish = 0;
}
}.start();
}
private void initTimeView() {
LogService.log(TAG, "---------------------------------------Init TIme VIEW, time to count: " + Constants.timeToCount);
LogService.log(TAG, "---------------------------------------Init TIme VIEW, time to count: " + PersistentUtil.getTimeToCount(ActivityRemainingTime.this));
bitmapgol = Bitmap.createBitmap(displayWidth, displayHeight, Config.ARGB_8888);
Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.background);
try {
Bitmap bit = setMuttable(icon);
Canvas canvas = new Canvas(bit);
timeview = new TimeView(ActivityRemainingTime.this, bitmapgol, canvas);
tryPorterDuff();
timeV.addView(timeview);
timeview.setFullTime(Constants.timeToCount);
timeV.bringToFront();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (reminder != 0) {
timeToCount(Constants.timeToCount * 1000);
LogService.log(TAG, "Reminder != 0" + reminder);
Constants.exactTime = System.currentTimeMillis();
PersistentUtil.setTimeToCount(ActivityRemainingTime.this, Constants.timeToCount);
PersistentUtil.setExactTime(ActivityRemainingTime.this, Constants.exactTime);
initAlarmReceiver((Constants.timeToCount * 1000) - (reminder * 1000));
} else {
LogService.log(TAG, "Reminder == 0" + reminder);
}
}
private void tryPorterDuff() {
try {
Method setLayerTypeMethod = timeview.getClass().getMethod("setLayerType", new Class[] { int.class, Paint.class });
setLayerTypeMethod.invoke(timeview, new Object[] { 1, null });
} catch (NoSuchMethodException e) {
// Older OS, no HW acceleration anyway
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
findViewById(R.id.remaining_time_main).setBackgroundResource(R.drawable.background2);
}
private void initAlarmReceiver(int time) {
Intent intent = new Intent(ActivityRemainingTime.this, AlarmReceiver.class);
intent.setAction("intent_myaction_alarm");
pendingIntent = PendingIntent.getBroadcast(ActivityRemainingTime.this, 1, intent, 0);
alarmManager = (AlarmManager) ActivityRemainingTime.this.getSystemService(ActivityRemainingTime.this.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, (Constants.exactTime + time), pendingIntent);
LogService.log(TAG, "a fost initiat receiverul : " + (Constants.exactTime + time));
}
@Override
protected void onDestroy() {
LogService.log(TAG, "ondestroy");
if (t != null) {
t.cancel();
}
super.onDestroy();
}
/**
* Used to animate a view expansion. Increase view from 0 to wrap content.
*
* @param v
*/
public void expand(final View v) {
hoursNP.setOnValueChangedListener(valuechangedListener);
minutesNP.setOnValueChangedListener(valuechangedListener);
v.measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
final int targtetHeight = v.getMeasuredHeight();
v.getLayoutParams().height = 0;
v.setVisibility(View.VISIBLE);
Animation a = new Animation() {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
v.getLayoutParams().height = interpolatedTime == 1 ? LayoutParams.WRAP_CONTENT : (int) (targtetHeight * interpolatedTime);
v.requestLayout();
}
@Override
public boolean willChangeBounds() {
return true;
}
};
// 1dp/ms
a.setDuration((int) (targtetHeight / v.getContext().getResources().getDisplayMetrics().density));
v.startAnimation(a);
}
/**
* Used to animate a view collapse. Reduce size from wrap content to 0.
*
* @param v
*/
public void collapse(final View v) {
hoursNP.setOnValueChangedListener(null);
minutesNP.setOnValueChangedListener(null);
final int initialHeight = v.getMeasuredHeight();
Animation a = new Animation() {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
if (interpolatedTime == 1) {
v.setVisibility(View.GONE);
} else {
v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime);
v.requestLayout();
}
}
@Override
public boolean willChangeBounds() {
return true;
}
};
a.setDuration((int) (initialHeight / v.getContext().getResources().getDisplayMetrics().density));
a.setAnimationListener(animListener);
v.startAnimation(a);
}
/**
* Checks to see if the user selected the minimum required minutes in order to extend the parking time
*
* @return
*/
private boolean inputDataIsValid() {
// The parking time needs to be at least 10 minutes
if (minutesNP.getValue() == 0 && hoursNP.getValue() == 0) {
Tools.showInfoDialog(this, getString(R.string.main_validation_parking_time_title), getString(R.string.main_validation_parking_time_body));
return false;
}
return true;
}
private void calculateTime() {
Calendar calendar = Calendar.getInstance();
hourOfDay = calendar.get(Calendar.HOUR_OF_DAY);
int minOfDay = calendar.get(Calendar.MINUTE);
LogService.log(TAG, "hourOfDay : " + hourOfDay + ": " + minOfDay);
if (hourOfDay > 6 && hourOfDay < 20) {
int hours = Integer.parseInt(hoursNP.getDisplayedValues()[hoursNP.getValue()]);
int minutes = Integer.parseInt(minutesNP.getDisplayedValues()[minutesNP.getValue()]);
if (hours == 14) {
minutes = 0;
minutesNP.setValue(0);
}
timeAdded = Tools.getMinutes(hours, minutes);
int mintofinish = (int) (millistofinish / (1000 * 60));
int timeto8 = 1200 - (hourOfDay * 60 + minOfDay + mintofinish);
if (timeto8 < timeAdded) {
LogService.log(TAG, "timp mai mare decat ora 8");
timeAdded = timeto8;
}
String cost = getString(R.string.main_cost_header) + ": <b>";
double chf;
DecimalFormat df = new DecimalFormat("0.00");
if (taxes.size() > 1) {
if (timeAdded > taxes.get(0).getMinutes()) {
LogService.log(TAG, "------------");
chf = taxes.get(0).getMinutes() * (float) (taxes.get(0).getPrice() / 60f);
int minus = taxes.get(0).getMinutes();
for (int i = 1; i < taxes.size(); i++) {
if (timeAdded > taxes.get(i).getMinutes()) {
chf += ((taxes.get(i).getMinutes() - minus) * (float) (taxes.get(i).getPrice() / 60f));
minus = taxes.get(i).getMinutes();
LogService.log(TAG, "min: " + taxes.get(i).getMinutes() + " /price:" + taxes.get(i).getPrice() + " /minus:" + minus + " /chf: " + chf);
} else {
chf += ((timeAdded - minus) * (float) (taxes.get(i).getPrice() / 60f));
LogService.log(TAG, "min: " + timeAdded + " /price:" + taxes.get(i).getPrice() + " /minus:" + minus + " /chf: " + chf);
break;
}
}
LogService.log(TAG, "------------");
} else {
chf = timeAdded * (float) (taxes.get(0).getPrice() / 60f);
LogService.log(TAG, "min: " + timeAdded + " /price:" + taxes.get(0).getPrice() + " /chf: " + chf);
}
} else {
chf = timeAdded * (float) (taxes.get(0).getPrice() / 60f);
}
cost += df.format(chf);
cost += "</b> ";
cost += "CHF"; // TODO: replace with currency got from webservice
((TextView) findViewById(R.id.cost)).setText(Html.fromHtml(cost));
LogService.log(TAG, "timeadded: " + timeAdded);
}
}
public Bitmap setMuttable(Bitmap bitmap) throws Exception {
File file = new File("/mnt/sdcard/sample/temp.txt");
file.getParentFile().mkdirs();
randomAccessFile = new RandomAccessFile(file, "rw");
int bWidth = bitmap.getWidth();
int bHeight = bitmap.getHeight();
FileChannel channel = randomAccessFile.getChannel();
MappedByteBuffer map = channel.map(MapMode.READ_WRITE, 0, bWidth * bHeight * 4);
bitmap.copyPixelsToBuffer(map);
bitmap.recycle();
Bitmap bit;
bit = Bitmap.createBitmap(bWidth, bHeight, bitmap.getConfig());
map.position(0);
bit.copyPixelsFromBuffer(map);
channel.close();
randomAccessFile.close();
return bit;
}
}