안녕하세요.
위젯 작업 중인 개발자 입니다.
현재 위젯에서 설정창을 만들고 있습니다.
이미지뷰에 두개의 이미지를 띄우고, seekbar 값에 따라 투명도 조절을 할려고 합니다.
현재 액티비티 자체의 투명도는 실시간으로 setalpha가 적용되서, 수정이 되는데
이미지뷰나, 다른 뷰들을 설정하려고 하니 계속 문제가 생기네요.
아래는 소스코드 입니다.
package nl.xservices.plugins;
import com.google.android.gms.internal.hd;
import android.R.drawable;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.appwidget.AppWidgetManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.drawable.Drawable;
import android.media.Image;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.GridLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RemoteViews;
import android.widget.SeekBar;
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public class WidgetOption extends Activity implements OnClickListener{
private static final String TAG = "WidgetOption class";
private int appWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
//private int appWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
private LinearLayout mScreen;
GridLayout OptionScreen;
private ImageView sampleB, sampleW;
private Image im;
private SeekBar sb;
public static final String SeekValue = "SeekValue";
private int sbValue;
private ListView lv;
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle saveInstanceState)
{
Log.d(TAG, "======================= onCreate() =======================");
super.onCreate(saveInstanceState);
Log.d(TAG, "======================= 1 =======================");
setContentView(com.example.pa.R.layout.widgetoption);
assignAppWidgetId();
findViewById(com.example.pa.R.id.optionbtn).setOnClickListener(this);
sb = (SeekBar) findViewById(com.example.pa.R.id.seekBar1);
mScreen = (LinearLayout) findViewById(com.example.pa.R.id.h_calendar_layout);
OptionScreen = (GridLayout) findViewById(com.example.pa.R.id.OptionLayout);
sampleB = (ImageView)findViewById(com.example.pa.R.id.imageView2);
sampleW = (ImageView)findViewById(com.example.pa.R.id.imageView1);
lv = (ListView) findViewById(com.example.pa.R.id.listView1);
//updateBackground();
Log.d(TAG, "======================= update end =======================");
sb.setOnSeekBarChangeListener(seekBarChangeListener);
Log.d(TAG, "======================= 2 =======================");
}
private void assignAppWidgetId() {
Log.d(TAG, "======================= assignAppWidgetId =======================");
Bundle extras = getIntent().getExtras();
if (extras != null)
appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
}
@Override
public void onClick(View v) {
Log.d(TAG, "======================= onClick =======================");
if (v.getId() == com.example.pa.R.id.optionbtn)
{
Log.d("TAG", "btn click");
startWidget();
}
}
private SeekBar.OnSeekBarChangeListener seekBarChangeListener = new SeekBar.OnSeekBarChangeListener()
{
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
Log.d(TAG, "======================= onProgressChanged =======================");
updateBackground();
}
public void onStartTrackingTouch(SeekBar seekBar)
{
}
public void onStopTrackingTouch(SeekBar seekBar)
{
}
};
@SuppressWarnings("deprecation")
private void updateBackground() {
Log.d(TAG, "======================= updateBackground =======================");
final Context context = WidgetOption.this;
SharedPreferences pref = context.getSharedPreferences(SeekValue, Activity.MODE_PRIVATE);
sbValue = pref.getInt(String.valueOf(sbValue), 0);
Editor e = pref.edit();
sbValue = sb.getProgress(); // Á¤¼ö°ª º¯°æ
e.putInt(SeekValue, sbValue); // °ªÀ» ÀúÀåÇÔ
e.commit(); // ±â·Ï ½Ã۱â
Log.d(TAG,String.valueOf(sbValue));
Log.d(TAG,"2");
Drawable d = sampleB.getBackground();
Drawable d1 = OptionScreen.getBackground();
d.setAlpha(sbValue/* + sbValue * 0x10000*/);
d1.setAlpha(sbValue/* + sbValue * 0x10000*/);
//sampleB.setAlpha(sbValue);
//sampleW.setAlpha(sbValue);
//OpntionScreen.setAlpha(sbValue);
Log.d(TAG,"3");
}
private void startWidget() {
final Context context = WidgetOption.this;
AppWidgetManager widgetMgr = AppWidgetManager.getInstance(context);
Log.d("TAG", "start Widget Function");
Intent intent = new Intent();
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
setResult(Activity.RESULT_OK, intent);
Intent serviceIntent = new Intent(this, RemoteFetchService.class);
serviceIntent
.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
startService(serviceIntent);
widgets.updateWidget(context, widgetMgr, appWidgetId);
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
setResult(RESULT_OK, resultValue);
this.finish();
}
}
아래의 drawable 변수 선언해서 이미지뷰의 백그라운드 가져오는 부분
Drawable d = sampleB.getBackground();
에서 문제가 생기는 것 같습니다.
혹시 제가 놓치고 잇는 부분이 잇는지 조언 부탁드립니다.
감사합니다.