结构图:
基类:
package ch.halcyon.squareprogressbar.example;

import android.app.Activity;
import android.app.FragmentManager;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView; import java.util.ArrayList; import ch.halcyon.squareprogressbar.example.dialogs.CustomColourDialog;
import ch.halcyon.squareprogressbar.example.dialogs.PercentDialog;
import ch.halcyon.squareprogressbar.utils.ColourUtil; public class MainActivity extends Activity {
private DrawerLayout drawerLayout;
private ListView drawerListView;
private ActionBarDrawerToggle drawerToggle; private CharSequence drawerTitle;
private CharSequence title;
public static String[] partTitle, descriptions;
private SquareFragment squareFragment; private int lastPosition; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FragmentManager fragmentManager = getFragmentManager();
squareFragment = new SquareFragment();
fragmentManager.beginTransaction()
.replace(ch.halcyon.squareprogressbar.example.R.id.content_frame, squareFragment).commit();
setContentView(ch.halcyon.squareprogressbar.example.R.layout.activity_main); title = drawerTitle = getTitle();
partTitle = getResources().getStringArray(ch.halcyon.squareprogressbar.example.R.array.drawer_titel);
descriptions = getResources().getStringArray(
ch.halcyon.squareprogressbar.example.R.array.drawer_descriptions);
drawerLayout = (DrawerLayout) findViewById(ch.halcyon.squareprogressbar.example.R.id.drawer_layout);
drawerListView = (ListView) findViewById(ch.halcyon.squareprogressbar.example.R.id.left_drawer); drawerLayout.setDrawerShadow(ch.halcyon.squareprogressbar.example.R.drawable.drawer_shadow,
GravityCompat.START);
BaseAdapter adapter = new BaseAdapter() {
//获得视图
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
View item = convertView; //首项
View headerItem = LayoutInflater.from(getApplicationContext())
.inflate(ch.halcyon.squareprogressbar.example.R.layout.lv_header_layout, parent, false);
TextView title = (TextView) headerItem
.findViewById(ch.halcyon.squareprogressbar.example.R.id.lv_list_hdr); //自定义项目
View styleItem = LayoutInflater.from(getApplicationContext())
.inflate(ch.halcyon.squareprogressbar.example.R.layout.lv_style, parent, false);
CheckBox box = (CheckBox) styleItem
.findViewById(ch.halcyon.squareprogressbar.example.R.id.checkBox1); View styleBoxItem = LayoutInflater
.from(getApplicationContext()).inflate(
ch.halcyon.squareprogressbar.example.R.layout.lv_style_box, parent, false);
final CheckBox styleBox = (CheckBox) styleBoxItem
.findViewById(ch.halcyon.squareprogressbar.example.R.id.checkBox11);
ImageView styleImage = (ImageView) styleBoxItem
.findViewById(ch.halcyon.squareprogressbar.example.R.id.imageView1); // 链接到Github
View githubItem = LayoutInflater.from(getApplicationContext())
.inflate(ch.halcyon.squareprogressbar.example.R.layout.lv_github, parent, false);
TextView githublink = (TextView) githubItem
.findViewById(ch.halcyon.squareprogressbar.example.R.id.textView1); // 链接到homepage
View signerItem = LayoutInflater.from(getApplicationContext())
.inflate(ch.halcyon.squareprogressbar.example.R.layout.lv_signer, parent, false); // 链接到Image
View imageItem = LayoutInflater.from(getApplicationContext())
.inflate(ch.halcyon.squareprogressbar.example.R.layout.lv_image, parent, false);
ImageView imagePreview = (ImageView) imageItem
.findViewById(ch.halcyon.squareprogressbar.example.R.id.imageView1);
TextView imageDesc = (TextView) imageItem
.findViewById(ch.halcyon.squareprogressbar.example.R.id.imagetag); switch (position) {
case :
title.setText("Colour");
return headerItem;
case :
Context context = getApplicationContext();
item = LayoutInflater.from(context).inflate(
ch.halcyon.squareprogressbar.example.R.layout.lv_colour_text, parent, false);
item.setOnClickListener(new OnClickListener() { @Override
public void onClick(View arg0) {
final CustomColourDialog customColourDialog = new CustomColourDialog(
MainActivity.this);
customColourDialog.show();
customColourDialog.getSaveButton()
.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
squareFragment.squareProgressBar
.setColorRGB(customColourDialog
.getChoosenRGB());
customColourDialog.dismiss(); }
});
selectItem(position);
lastPosition = position;
}
});
TextView textView = (TextView) item
.findViewById(ch.halcyon.squareprogressbar.example.R.id.colour_name_center);
textView.setText("choose RGB colour");
return item;
case :
title.setText("Style");
return headerItem; case :
box.setText(ch.halcyon.squareprogressbar.example.R.string.opacity);
box.setChecked(squareFragment.squareProgressBar.isOpacity());
box.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
squareFragment.squareProgressBar
.setOpacity(isChecked);
}
});
return styleItem; case :
box.setText("Outline");
box.setChecked(squareFragment.squareProgressBar.isOutline());
box.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
squareFragment.squareProgressBar
.drawOutline(isChecked);
}
});
return styleItem; case :
box.setText("Startline");
box.setChecked(squareFragment.squareProgressBar
.isStartline());
box.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
squareFragment.squareProgressBar
.drawStartline(isChecked);
}
});
return styleItem; case :
box.setText("Centerline");
box.setChecked(squareFragment.squareProgressBar
.isCenterline());
box.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
squareFragment.squareProgressBar
.drawCenterline(isChecked);
}
});
return styleItem; case :
styleBox.setText("Show percent");
styleBox.setChecked(squareFragment.squareProgressBar
.isShowProgress());
styleBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
squareFragment.squareProgressBar
.showProgress(isChecked);
}
});
styleImage.setOnClickListener(new OnClickListener() { @Override
public void onClick(View arg0) {
final PercentDialog percentDialog = new PercentDialog(
MainActivity.this);
percentDialog.show();
percentDialog
.setPercentStyle(squareFragment.squareProgressBar
.getPercentStyle());
percentDialog.getSaveButton().setOnClickListener(
new OnClickListener() { @Override
public void onClick(View v) {
squareFragment.squareProgressBar
.setPercentStyle(percentDialog
.getSettings());
percentDialog.dismiss();
styleBox.setChecked(true);
drawerLayout.closeDrawers();
}
});
}
});
return styleBoxItem; case :
box.setText("Grayscale");
box.setChecked(squareFragment.squareProgressBar
.isGreyscale());
box.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
squareFragment.squareProgressBar
.setImageGrayscale(isChecked);
}
});
return styleItem;
case :
box.setText("Clear at 100%");
box.setChecked(squareFragment.squareProgressBar
.isClearOnHundred());
box.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
squareFragment.squareProgressBar
.setClearOnHundred(isChecked);
}
});
return styleItem; case :
box.setText("Indeterminate");
box.setChecked(squareFragment.squareProgressBar
.isIndeterminate());
box.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
squareFragment.squareProgressBar
.setIndeterminate(isChecked);
}
});
return styleItem; case :
title.setText("Image");
return headerItem;
case :
imagePreview.setImageResource(ch.halcyon.squareprogressbar.example.R.drawable.blenheim_palece);
imageDesc.setText("blenheim palace");
imageItem.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
squareFragment.squareProgressBar
.setImage(ch.halcyon.squareprogressbar.example.R.drawable.blenheim_palece);
}
});
return imageItem;
case :
imagePreview
.setImageResource(ch.halcyon.squareprogressbar.example.R.drawable.millennium_stadium);
imageDesc.setText("the millennium stadium");
imageItem.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
squareFragment.squareProgressBar
.setImage(ch.halcyon.squareprogressbar.example.R.drawable.millennium_stadium);
}
});
return imageItem;
case :
imagePreview.setImageResource(ch.halcyon.squareprogressbar.example.R.drawable.edinburgh);
imageDesc.setText("carlton hill");
imageItem.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
squareFragment.squareProgressBar
.setImage(ch.halcyon.squareprogressbar.example.R.drawable.edinburgh);
}
});
return imageItem;
case :
imagePreview.setImageResource(ch.halcyon.squareprogressbar.example.R.drawable.holyroodpark);
imageDesc.setText("holyrood park");
imageItem.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
squareFragment.squareProgressBar
.setImage(ch.halcyon.squareprogressbar.example.R.drawable.holyroodpark);
}
});
return imageItem;
case :
imagePreview.setImageResource(ch.halcyon.squareprogressbar.example.R.drawable.operahuset);
imageDesc.setText("operahuset oslo");
imageItem.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
squareFragment.squareProgressBar
.setImage(ch.halcyon.squareprogressbar.example.R.drawable.operahuset);
}
});
return imageItem;
case :
title.setText("Source");
return headerItem;
case :
String text = "<font color=#4183C4>mrwonderman</font>/<b><font color=#4183C4>android-square-progressbar</font></b> (v. 1.6.0)";
githublink.setText(Html.fromHtml(text));
githubItem.setOnClickListener(new OnClickListener() { @Override
public void onClick(View arg0) {
Intent browserIntent = new Intent(
Intent.ACTION_VIEW,
Uri.parse("https://github.com/mrwonderman/android-square-progressbar"));
startActivity(browserIntent);
}
});
return githubItem;
case :
signerItem.setOnClickListener(new OnClickListener() { @Override
public void onClick(View arg0) {
Intent browserIntent = new Intent(
Intent.ACTION_VIEW, Uri
.parse("http://www.halcyon.ch/"));
startActivity(browserIntent);
}
});
return signerItem;
default:
break;
}
//获得颜色数组
ArrayList<Integer> colourArray = ColourUtil.getColourArray(); if (position <= ) {
Context context = getApplicationContext();
item = LayoutInflater.from(context).inflate(
ch.halcyon.squareprogressbar.example.R.layout.lv_colour, parent, false);
View colourView = item.findViewById(ch.halcyon.squareprogressbar.example.R.id.colour_preview);
final Integer integer = colourArray.get(position - );
colourView.setBackgroundColor(context.getResources()
.getColor(integer));
item.setOnClickListener(new OnClickListener() { @Override
public void onClick(View arg0) {
squareFragment.squareProgressBar
.setHoloColor(integer);
selectItem(position);
lastPosition = position;
}
});
TextView textView = (TextView) item
.findViewById(ch.halcyon.squareprogressbar.example.R.id.colour_name);
textView.setText(getName(position - ));
}
return item;
} @Override
public long getItemId(int position) {
return position;
} @Override
public Object getItem(int position) {
return position;
} @Override
public int getCount() {
return ;
}
};
drawerListView.setAdapter(adapter);
drawerListView.setOnItemClickListener(new DrawerItemClickListener()); getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true); drawerToggle = new ActionBarDrawerToggle(this, drawerLayout,
ch.halcyon.squareprogressbar.example.R.drawable.ic_drawer, ch.halcyon.squareprogressbar.example.R.string.drawer_open,
ch.halcyon.squareprogressbar.example.R.string.drawer_close) {
@Override
public void onDrawerClosed(View view) {
getActionBar().setTitle(title);
invalidateOptionsMenu();
}
//开启
@Override
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle(drawerTitle);
invalidateOptionsMenu();
}
};
drawerLayout.setDrawerListener(drawerToggle);
}
//回调方法
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (drawerToggle.onOptionsItemSelected(item)) {
return true;
}
return true;
}
//选项菜单
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
return super.onPrepareOptionsMenu(menu);
} @Override
public void setTitle(CharSequence title) {
this.title = title;
getActionBar().setTitle(title);
} @Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
drawerToggle.syncState();
}
//横竖屏转换
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
drawerToggle.onConfigurationChanged(newConfig);
}
//获得名字的序列
private CharSequence getName(int position) {
switch (position) {
case :
return "holo_blue_bright";
case :
return "holo_blue_dark";
case :
return "holo_blue_light";
case :
return "holo_green_dark";
case :
return "holo_green_light";
case :
return "holo_orange_dark";
case :
return "holo_orange_light";
case :
return "holo_purple";
case :
return "holo_red_dark";
case :
return "holo_red_light"; default:
break;
}
return "";
} private void selectItem(int position) {
drawerListView.setItemChecked(position, true);
}
//点击事件监听器
private class DrawerItemClickListener implements
ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
if ((position != ) && (position != ) && (position != )
&& (position != )) {
selectItem(position);
} else {
selectItem(lastPosition);
}
}
}
}

MainActivity

创建PreviewView类继承View
package ch.halcyon.squareprogressbar.example;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View; public class PreviewView extends View { private final Paint paintPaint;
//中心对齐
private Align center = Align.CENTER;
private float size = ;
private boolean b = true;
//预览视图
public PreviewView(Context context) {
super(context);
paintPaint = new Paint();
paintPaint.setColor(context.getResources().getColor(
android.R.color.black));
paintPaint.setAntiAlias(true);
paintPaint.setStyle(Style.STROKE);
} public PreviewView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle); paintPaint = new Paint();
paintPaint.setColor(context.getResources().getColor(
android.R.color.black));
paintPaint.setAntiAlias(true);
paintPaint.setStyle(Style.STROKE);
} public PreviewView(Context context, AttributeSet attrs) {
super(context, attrs); paintPaint = new Paint();
paintPaint.setColor(context.getResources().getColor(
android.R.color.black));
paintPaint.setAntiAlias(true);
paintPaint.setStyle(Style.STROKE);
} @Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Path path = new Path();
path.moveTo(, );
path.lineTo(, canvas.getWidth());
path.lineTo(canvas.getHeight(), canvas.getWidth());
path.lineTo(canvas.getHeight(), );
path.lineTo(, );
canvas.drawPath(path, paintPaint);
paintPaint.setTextAlign(center);
paintPaint.setTextSize(Float.valueOf(String.valueOf(size)));
canvas.drawText(b ? "32%" : "", canvas.getWidth() / , (int) ((canvas
.getHeight() / ) - ((paintPaint.descent() + paintPaint
.ascent()) / )), paintPaint);
} public void drawText(int size, Align center, boolean b) {
this.size = size;
this.center = center;
this.b = b;
this.invalidate();
} }

PreviewView

创建SquareFragment类继承Fragment
package ch.halcyon.squareprogressbar.example;

import ch.halcyon.squareprogressbar.SquareProgressBar;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView; public class SquareFragment extends Fragment {
public SquareProgressBar squareProgressBar; @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(ch.halcyon.squareprogressbar.example.R.layout.square_layout, container, false);
squareProgressBar = (SquareProgressBar) view.findViewById(ch.halcyon.squareprogressbar.example.R.id.subi2);
squareProgressBar.setImage(ch.halcyon.squareprogressbar.example.R.drawable.blenheim_palece);
squareProgressBar.setColor("#C9C9C9");
squareProgressBar.setProgress();
squareProgressBar.setWidth(); final TextView progressView = (TextView) view
.findViewById(ch.halcyon.squareprogressbar.example.R.id.progressDisplay);
progressView.setText("32%"); SeekBar progressSeekBar = (SeekBar) view
.findViewById(ch.halcyon.squareprogressbar.example.R.id.progressSeekBar);
progressSeekBar
.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override
public void onStopTrackingTouch(SeekBar seekBar) {
// nothing to do
} @Override
public void onStartTrackingTouch(SeekBar seekBar) {
// nothing to do
} @Override
public void onProgressChanged(SeekBar seekBar,
int progress, boolean fromUser) {
squareProgressBar.setProgress(progress);
progressView.setText(progress + "%");
}
}); SeekBar widthSeekBar = (SeekBar) view.findViewById(ch.halcyon.squareprogressbar.example.R.id.widthSeekBar);
widthSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override
public void onStopTrackingTouch(SeekBar seekBar) {
// nothing to do
} @Override
public void onStartTrackingTouch(SeekBar seekBar) {
// nothing to do
} @Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
squareProgressBar.setWidth(progress);
}
});
return view;
} }

SquareFragment

创建CustomColourDialog类并且继承Dialog:

package ch.halcyon.squareprogressbar.example.dialogs;

import ch.halcyon.squareprogressbar.example.R;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView; public class CustomColourDialog extends Dialog { private final Button saveButton;
private SeekBar rSeekBar;
private SeekBar gSeekBar;
private SeekBar bSeekBar;
private int choosenRGB; public CustomColourDialog(final Context context) {
super(context);
//舍去标题
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.setContentView(R.layout.customcolourdialog);
this.setCancelable(false); Button closeButton = (Button) this
.findViewById(R.id.returnColourDialog);
closeButton.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) {
dismiss();
}
});
saveButton = (Button) this.findViewById(R.id.shareColourDialog); rSeekBar = (SeekBar) findViewById(R.id.rSeekBar);
rSeekBar.setMax();
rSeekBar.setProgress();
rSeekBar.setOnSeekBarChangeListener(rgbOnSeekBarListener()); gSeekBar = (SeekBar) findViewById(R.id.gSeekBar);
gSeekBar.setMax();
gSeekBar.setProgress();
gSeekBar.setOnSeekBarChangeListener(rgbOnSeekBarListener()); bSeekBar = (SeekBar) findViewById(R.id.bSeekBar);
bSeekBar.setMax();
bSeekBar.setProgress();
bSeekBar.setOnSeekBarChangeListener(rgbOnSeekBarListener()); calculateRGB(); } private OnSeekBarChangeListener rgbOnSeekBarListener() {
return new OnSeekBarChangeListener() { @Override
public void onStopTrackingTouch(SeekBar arg0) {
// nothing to do =)
} @Override
public void onStartTrackingTouch(SeekBar arg0) {
// nothing to do =) } @Override
public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
calculateRGB();
}
};
} public Button getSaveButton() {
return saveButton;
}
//计算颜色属性值
private void calculateRGB() {
int r = rSeekBar.getProgress();
int g = gSeekBar.getProgress();
int b = bSeekBar.getProgress();
((TextView) findViewById(R.id.rgbText)).setText("(" + r + "," + g + ","
+ b + ")");
choosenRGB = Color.rgb(r, g, b);
getWindow().setBackgroundDrawable(new ColorDrawable(choosenRGB));
} /**
* Returns the Color which was chosen in the Dialog.
*
* @return the chosen RGB-colour.
*/
public int getChoosenRGB() {
return choosenRGB;
}
}

CustomColourDialog

创建PercentDialog类并且继承Dialog:
package ch.halcyon.squareprogressbar.example.dialogs;

import ch.halcyon.squareprogressbar.example.PreviewView;
import ch.halcyon.squareprogressbar.utils.PercentStyle;
import ch.halcyon.squareprogressbar.example.R; import android.app.Dialog;
import android.content.Context;
import android.graphics.Paint.Align;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.Spinner;
import android.widget.TextView; public class PercentDialog extends Dialog { private final Spinner spinner;
private final CheckBox box;
private final Button saveButton;
private final SeekBar bar;
private int size;
private final PreviewView previewView; public PercentDialog(final Context context) {
super(context);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.setContentView(R.layout.percentdialog);
this.setCancelable(false);
spinner = (Spinner) this.findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
context, R.array.alignstyle,
android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter); previewView = (PreviewView) findViewById(R.id.previewView1);
spinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
redrawPreview();
} @Override
public void onNothingSelected(AdapterView<?> arg0) {
// nothing to do =)
}
}); Button closeButton = (Button) this.findViewById(R.id.returnDialog);
closeButton.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) {
dismiss(); }
});
saveButton = (Button) this.findViewById(R.id.shareDialog); final TextView progress = (TextView) findViewById(R.id.textView3); bar = (SeekBar) findViewById(R.id.textSize);
bar.setMax();
bar.setProgress();
bar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override
public void onStopTrackingTouch(SeekBar arg0) {
// nothing to do =)
} @Override
public void onStartTrackingTouch(SeekBar arg0) {
// nothing to do =) } @Override
public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
size = arg1;
progress.setText(arg1 + " dp");
redrawPreview();
}
}); box = (CheckBox) this.findViewById(R.id.checkBox1);
box.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
redrawPreview();
}
}); } public PercentStyle getSettings() {
return new PercentStyle(Align.valueOf((String) spinner
.getSelectedItem()), Float.valueOf(bar.getProgress()),
box.isChecked());
} public Button getSaveButton() {
return saveButton;
} private Align returnAlign(int position) {
switch (position) {
case :
return Align.CENTER;
case :
return Align.RIGHT;
case :
return Align.LEFT;
default:
return Align.CENTER;
}
} private void redrawPreview() {
previewView
.drawText(size, returnAlign(spinner.getSelectedItemPosition()),
box.isChecked());
} public void setPercentStyle(PercentStyle settings) {
switch (settings.getAlign()) {
case CENTER:
spinner.setSelection();
break;
case RIGHT:
spinner.setSelection();
break;
case LEFT:
spinner.setSelection();
break;
default:
spinner.setSelection();
break;
} bar.setProgress(Math.round(settings.getTextSize()));
box.setChecked(settings.isPercentSign());
}
}

PercentDialog

Android之图片窗口和大小调节的更多相关文章

  1. Android RecyclerView的item大小保持四个半

        现在有这么一个需求,实现下图的UI.  我想你应该能想到用RecyclerView实现, 当我唰唰唰几分钟做完之后,UI设计师跟我说,每个item,无论在什么手机上,都要显示四个半,具体看下图 ...

  2. Android之计算缓存大小并且清空缓存

    转载博客:http://www.2cto.com/kf/201503/385492.html 项目中碰到了计算缓存大小和清空缓存的功能,这个很常见的功能,几乎每个APP都有,以为实现很简单,网上搜了一 ...

  3. android px,dp,sp大小转换工具

    package com.voole.playerlib.util; import android.content.Context; /** * Android大小单位转换工具类<br/> ...

  4. 转-android图片降低图片大小保持图片清晰的方法

    http://i.cnblogs.com/EditPosts.aspx?opt=1 android里面对于图片的处理一直是个比较烦人的问题,烦人之处在于一个不小心,就有可能造成OOM. 最近碰到一个关 ...

  5. 【转载】Android Studio 设置内存大小及原理

    http://www.cnblogs.com/justinzhang/p/4274985.html http://tsroad.lofter.com/post/376316_69363ae Andro ...

  6. Android中设置文字大小的定义类型

    在Android中所有的组件可以设置大小,但是在设置大小的时候需要指定其单位,这些单位如下: px(pixels):像素: dip(device independent pixels):依赖于设备的像 ...

  7. RN无限轮播以及ScrollView的大小调节问题

    如果你的ScrollView的大小是全屏,height不能用,这种情况需要给ScrollView添加一个容器View,然后调节容器View的大小 无限轮播这里我使用的是一个第三方的插件react-na ...

  8. 6.关于Xamarin Android对APK包大小的处理

    降低学习成本是每个.NET传教士义务与责任. 建立生态,保护生态,见者有份. 对于apk 包的大小大家都是很敏感的,虽然现在安卓手机的性能和存储越来越厉害了.本着能少一点是一点的态度,我们还是要深入理 ...

  9. Android Studio修改字体大小

    android studio提供的主题是不能修改字体和字体大小的,如果要修改大小就的另存一份自定义的主题了. 1.启动Android Studio,菜单"File"-"S ...

随机推荐

  1. OpenNebula config配置详情

    AUTH_MAD=AUTHN=ssh,x509,ldap,server_cipher,server_x509,EXECUTABLE=one_auth_mad DATASTORE_BASE_PATH=/ ...

  2. Codeforces Round #114 (Div. 1) A. Wizards and Trolleybuses 物理题

    A. Wizards and Trolleybuses Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...

  3. Codeforces Gym 100610 Problem A. Alien Communication Masterclass 构造

    Problem A. Alien Communication Masterclass Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codefo ...

  4. AES加密算法(C++实现,附源代码)

    先搞定AES算法,基本变换包含SubBytes(字节替代).ShiftRows(行移位).MixColumns(列混淆).AddRoundKey(轮密钥加) 其算法一般描写叙述为 明文及密钥的组织排列 ...

  5. 05.pathinfo的两种模式与模版和控制器之间的关系

    <?php function dump($data){ echo '<pre>'; var_dump($data); echo '</pre>'; } dump($_SE ...

  6. [MODX] 2. Chunks $

    Chunk in Modx can cut your template into samll pieces to make code reuseable. [[$chunk_name]] For ex ...

  7. HDU1013_Digital Roots【大数】【水题】

    Digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  8. iOS开发——UI篇&九宫格算法

    九宫格算法 关于iOS开发中九宫格的实现虽然使用不多,而且后面会有更好的方实现,但是作为一个程序员必需要知道的就是九宫格算法的实现. 一:实现思路: (1)明确每一块用得是什么view (2)明确每个 ...

  9. Linux下的简单好用的计算器bc

    1. 关于bc bc是随意精度计算器语言,通常在linux下当计算器用,简单好用.相当于windows下的计算器. 2. 支持的运算符 主要的数学运算: + 加法 - 减法 * 乘法 / 除法 ^ 指 ...

  10. Fedora 20 安装后的一些事情

    1.关闭selinux 可以在软件中,找到selinux管理工具:system-config-selinux.py 2.安装源 可以通过# ls -l /etc/yum.repos.d 查看现有的安装 ...