• Forumda özel mesajlaşmalar kapalıdır. İstek, öneri, şikayet durumunda buraya konu açabilirsiniz.



android widget anlayanlar

ANDROİD34

Üye
Katılım
20 May 2019
Mesajlar
1
merhaba bir tane hatırlatıcı uygulamam var bu uygulamaya widget eklemek istiyorum ama widgettan anlamıyorum
package com.example.bitirmehatirlatici;

import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.amulyakhare.textdrawable.TextDrawable;
import com.amulyakhare.textdrawable.util.ColorGenerator;
import com.example.bitirmehatirlatici.data.AlarmReminderContract;



public class AlarmCursorAdapter extends CursorAdapter {

private TextView mTitleText, mDateAndTimeText, mRepeatInfoText;
private ImageView mActiveImage , mThumbnailImage;
private ColorGenerator mColorGenerator = ColorGenerator.DEFAULT;
private TextDrawable mDrawableBuilder;

public AlarmCursorAdapter(Context context, Cursor c) {
super(context, c, 0 /* flags */);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return LayoutInflater.from(context).inflate(R.layout.alarm_items, parent, false);
}

@Override
public void bindView(View view, Context context, Cursor cursor) {

mTitleText = view.findViewById(R.id.recycle_title);
mDateAndTimeText = view.findViewById(R.id.recycle_date_time);
mRepeatInfoText = view.findViewById(R.id.recycle_repeat_info);
mActiveImage = view.findViewById(R.id.active_image);
mThumbnailImage = view.findViewById(R.id.thumbnail_image);

int titleColumnIndex = cursor.getColumnIndex(AlarmReminderContract.AlarmReminderEntry.KEY_TITLE);
int dateColumnIndex = cursor.getColumnIndex(AlarmReminderContract.AlarmReminderEntry.KEY_DATE);
int timeColumnIndex = cursor.getColumnIndex(AlarmReminderContract.AlarmReminderEntry.KEY_TIME);
int repeatColumnIndex = cursor.getColumnIndex(AlarmReminderContract.AlarmReminderEntry.KEY_REPEAT);
int repeatNoColumnIndex = cursor.getColumnIndex(AlarmReminderContract.AlarmReminderEntry.KEY_REPEAT_NO);
int repeatTypeColumnIndex = cursor.getColumnIndex(AlarmReminderContract.AlarmReminderEntry.KEY_REPEAT_TYPE);
int activeColumnIndex = cursor.getColumnIndex(AlarmReminderContract.AlarmReminderEntry.KEY_ACTIVE);

String title = cursor.getString(titleColumnIndex);
String date = cursor.getString(dateColumnIndex);
String time = cursor.getString(timeColumnIndex);
String repeat = cursor.getString(repeatColumnIndex);
String repeatNo = cursor.getString(repeatNoColumnIndex);
String repeatType = cursor.getString(repeatTypeColumnIndex);
String active = cursor.getString(activeColumnIndex);




setReminderTitle(title);

if (date != null){
String dateTime = date + " " + time;
setReminderDateTime(dateTime);
}else{
mDateAndTimeText.setText("Tarih ayarlanmadı");
}

if(repeat != null){
setReminderRepeatInfo(repeat, repeatNo, repeatType);
}else{
mRepeatInfoText.setText("Tekrarlama ayarlanmadı");
}

if (active != null){
setActiveImage(active);
}else{
mActiveImage.setImageResource(R.drawable.ic_notifications_off_grey600_24dp);
}






}

// Set reminder title view
public void setReminderTitle(String title) {
mTitleText.setText(title);
String letter = "A";

if(title != null && !title.isEmpty()) {
letter = title.substring(0, 1);
}

int color = mColorGenerator.getRandomColor();

// Create a circular icon consisting of a random background colour and first letter of title
mDrawableBuilder = TextDrawable.builder()
.buildRound(letter, color);
mThumbnailImage.setImageDrawable(mDrawableBuilder);
}

// Set date and time views
public void setReminderDateTime(String datetime) {
mDateAndTimeText.setText(datetime);
}

// Set repeat views
public void setReminderRepeatInfo(String repeat, String repeatNo, String repeatType) {
if(repeat.equals("true")){
mRepeatInfoText.setText("Her " + repeatNo + " " + repeatType + "(de/da)");
}else if (repeat.equals("false")) {
mRepeatInfoText.setText("Tekrarlama Kapalı");
}
}

// Set active image as on or off
public void setActiveImage(String active){
if(active.equals("true")){
mActiveImage.setImageResource(R.drawable.ic_notifications_on_white_24dp);
}else if (active.equals("false")) {
mActiveImage.setImageResource(R.drawable.ic_notifications_off_grey600_24dp);
}

}
}
g//
//
bu klasta yapılan işlemi widget içinde yapmak istiyorum
//
//
package com.example.bitirmehatirlatici;

import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.widget.RemoteViews;

/**
* Implementation of App Widget functionality.
*/
public class Widget extends AppWidgetProvider {

static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
int appWidgetId) {

CharSequence widgetText = context.getString(R.string.appwidget_text);
// Construct the RemoteViews object
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
views.setTextViewText(R.id.appwidget_text, widgetText);

// Instruct the widget manager to update the widget
appWidgetManager.updateAppWidget(appWidgetId, views);
}

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
// There may be multiple widgets active, so update all of them
for (int appWidgetId : appWidgetIds) {
updateAppWidget(context, appWidgetManager, appWidgetId);
}
}

@Override
public void onEnabled(Context context) {
// Enter relevant functionality for when the first widget is created
}

@Override
public void onDisabled(Context context) {
// Enter relevant functionality for when the last widget is disabled
}
}
 

Üst Alt