2014年10月

Can i set min time as current time in timepickerdalog?

I have set min date as current date in the datePickerDialog using setMinDate().. Now i want to set the same to the timePickerDialog.. Is that possible ? if yes please help..



public class AddTasks extends Activity {

TaskForm activityForm = new TaskForm();

private Button pPickDate;
private int pYear;
private int pMonth;
private int pDay;
public String date;
public String Loc;
public double lat;
public double lon;

private Button pPickTime;
private int mHour;
private int mMinute;
public String time;

private TimePickerDialog timePickerDialog;
private DatePickerDialog datePickerDialog;

Date selectedDate;


/** This integer will uniquely define the dialog to be used for displaying date picker.*/
static final int DATE_DIALOG_ID = 0;
static final int TIME_DIALOG_ID = 1;

/** Callback received when the user "picks" a date in the dialog */
private DatePickerDialog.OnDateSetListener pDateSetListener =
new DatePickerDialog.OnDateSetListener() {

public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
pYear = year;
pMonth = monthOfYear;
pDay = dayOfMonth;
updateDate();
displayDateToast();
}
};

private TimePickerDialog.OnTimeSetListener mTimeListener =
new TimePickerDialog.OnTimeSetListener() {
public void onTimeSet(TimePicker view, int hour, int minute) {
mHour = hour;
mMinute = minute;
updateTime();
displayTimeToast();
}
};

/** Updates the date in the TextView */
private void updateDate() {
/** pDisplayDate.setText( */ date =
new StringBuilder()
// Month is 0 based so add 1
.append(pDay).append("/")
.append(pMonth + 1).append("/")
.append(pYear).append(" ").toString();
// date = pDisplayDate.getText().toString();

}

private void updateTime() {
/** pDisplayTime.setText( */ time =
new StringBuilder()
.append(mHour).append(":")
.append(mMinute).append("").toString();
}

/** Displays a notification when the date is updated */
private void displayDateToast() {
//Toast.makeText(this, new StringBuilder().append("Date choosen is ").append(date), Toast.LENGTH_LONG).show();
activityForm.setTaskDateInput(date);
}

private void displayTimeToast() {
// Toast.makeText(this, new StringBuilder().append("Time choosen is ").append(time), Toast.LENGTH_LONG).show();
activityForm.setTaskTimeInput(time);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add_task);
init();

/** Capture our View elements */
//pDisplayDate = (TextView) findViewById(R.id.displayDate);
pPickDate = (Button) findViewById(R.id.pickDate);

/** Listener for click event of the button */
pPickDate.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
showDialog(DATE_DIALOG_ID);
}
});

/** Capture our View elements */
//pDisplayTime = (TextView) findViewById(R.id.displayTime);
pPickTime = (Button) findViewById(R.id.pickTime);


/** Listener for click event of the button */
pPickTime.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
showDialog(TIME_DIALOG_ID);
}
});

/** Get the current date and time */
final Calendar cal = Calendar.getInstance();
pYear = cal.get(Calendar.YEAR);
pMonth = cal.get(Calendar.MONTH);
pDay = cal.get(Calendar.DAY_OF_MONTH);

mHour = cal.get(Calendar.HOUR_OF_DAY);
mMinute = cal.get(Calendar.MINUTE);
}

/** Create a new dialog for date and time picker */
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID:
datePickerDialog = new DatePickerDialog(this,
pDateSetListener,
pYear, pMonth, pDay);
Date dt = new Date();
Calendar calendar = new Calendar();
calendar.setTime(dt);
mHour = calendar.get(Calendar.HOUR_OF_DAY);
mMinute = calendar.get(Calendar.MINUTE);
datePickerDialog.getDatePicker().setMinDate(dt.getTime() - 10000);
// datePickerDialog.getDatePicker().setMinDate(new Date().getTime() - 10000);
return datePickerDialog;

case TIME_DIALOG_ID:
timePickerDialog = new TimePickerDialog(this,
mTimeListener,
mHour,mMinute,true) ;
return timePickerDialog;


}
return null;
}


I have Edited my Post by adding the whole code..



I have 2 buttons for datepickerdialog and timepickerdialog each.. what i want is when i click on the button and the dialog opens then the user should not be able to set past date or time in the dialog i.e dialog should show current date and time.. By setMinDate() on Datepickerdialog m able to do for date but for time there's no such method.. how can i do this.. ?



Answers

Try this out, you get the hour and minute from the datePickerDialog Date object when you set it to minimum date,



protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID:
datePickerDialog = new DatePickerDialog(this,
pDateSetListener,
pYear, pMonth, pDay);
Date dt = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(dt);
mHour = calendar.get(Calendar.HOUR_OF-DAY);
mMinute = calendar.get(Calendar.MINUTE);
datePickerDialog.getDatePicker().setMinDate(dt.getTime() - 10000);
return datePickerDialog;

case TIME_DIALOG_ID:
timePickerDialog = new TimePickerDialog(this,
mTimeListener,
mHour,mMinute,true) ;
return timePickerDialog;


}
return null;
}




Animation of y position for a Column centerd in parent

I have a Column with three elements and one element can change its visibility if the user hits the spacebar. To make the visibility change look smoothly I can add a move transition:



ApplicationWindow {
title: qsTr("Hello World")
width: 640
height: 480
visible: true

Column {
spacing: 2

Rectangle { color: "red"; width: 50; height: 50 }
Rectangle { id: greenRect; color: "green"; width: 20; height: 50 }
Rectangle { color: "blue"; width: 50; height: 20 }

move: Transition {
NumberAnimation { properties: "x,y"; duration: 1000 }
}

focus: true
Keys.onSpacePressed: greenRect.visible = !greenRect.visible
}
}


This works. But if I center the Column in its parent the visibility change also results in a new height for the Columnand therefore also to a new y position.



Now I don't want the Column to 'jump' to its new position but also to move smoothly. So I added this to the Column:



    anchors.centerIn: parent
Behavior on y {
NumberAnimation { duration: 1000 }
}


But the y position change is still not animated. How to achieve this?



Answers

I added another Item element which holds the Column. This allows you to set a Behavior on the item's height property and is what you're looking for:



import QtQuick 2.4
import QtQuick.Controls 1.3

ApplicationWindow {
width: 640
height: 480
visible: true

Item {
id: container
width: col.width
height: col.height
anchors.centerIn: parent
property int animationDuration: 200

Behavior on height {
PropertyAnimation {
duration: container.animationDuration
}
}

Column {
id: col
spacing: 2
focus: true

Rectangle { color: "red"; width: 50; height: 50 }
Rectangle { id: greenRect; color: "green"; width: 20; height: 50 }
Rectangle { color: "blue"; width: 50; height: 20 }

move: Transition {
NumberAnimation { properties: "x,y"; duration: container.animationDuration }
}

Keys.onSpacePressed: greenRect.visible = !greenRect.visible
}
}
}


Hope this helps!



Answers

Property changes induced by anchors don't seem to trigger Behaviours.



As a workaround, manually center the Column:



import QtQuick 2.2

Rectangle {
width: 640
height: 480

Column {
spacing: 2
anchors.horizontalCenter: parent.horizontalCenter
y: (parent.height - height) / 2

Behavior on y {
NumberAnimation { duration: 1000 }
}

Rectangle { color: "red"; width: 50; height: 50 }
Rectangle { id: greenRect; color: "green"; width: 20; height: 50 }
Rectangle { color: "blue"; width: 50; height: 20 }

move: Transition {
NumberAnimation { properties: "x,y"; duration: 1000 }
}

focus: true
Keys.onSpacePressed: greenRect.visible = !greenRect.visible
}
}




Assign And Weak

I want to look a difference between assign and weak.So I run this code below:



@interface Test : NSObject

@property(nonatomic, strong) NSString *str;
@property(nonatomic, assign) NSString *assignString;
@property(nonatomic, weak) NSString *weakString;

@end

@implementation Test

- (id)init
{
self =[super init];
if (self)
{
self.str = @"i'm test string";

self.assignString = self.str;
self.weakString = self.str;

self.str = nil;

NSLog(@"dealloc \nstr = %p\n assignstr = %p\n weakStr = %p\n", self.str, self.assignString, self.weakString);

NSLog(@"str = %@ \nassignStr = %@\n weakString = %@\n", self.str, self.assignString, self.weakString);
}

return self;
}

@end


I think it should output like this:




str = 0x0



assignString = 0x0



weakString = 0x0



str = (null)



assignString = (null)



weakString = (null)




But I get this output:




2015-06-17 11:22:04.676 AssignWeakDiff[4696:1897735]



str = 0x0



assignstr = 0x100002078



weakStr = 0x100002078



str = (null)



assignStr = i'm test string



weakString = i'm test string




It's there something wrong with my code?



Answers

As CRD said, strings have all sorts of optimizations that alter their memory management. Repeat this exercise with your own custom NSObject subclass and you should see traditional object lifecycle behaviors.


Your expected output for the assign property is incorrect. You should expect that to have a dangling pointer to the deallocated object. The assign reference is not set to nil automatically when the object is deallocated. The weak reference will, but the assign reference will not.




Thus, if you have properties like so:



@property (nonatomic, strong) MyObject *strongObj;
@property (nonatomic, assign) MyObject *assignObj;
@property (nonatomic, weak) MyObject *weakObj;


And then do:



self.strongObj = [[MyObject alloc] init];
self.assignObj = self.strongObj;
self.weakObj = self.strongObj;

NSLog(@"%@ %@ %@", self.strongObj, self.assignObj, self.weakObj);

self.strongObj = nil;

NSLog(@"%@ %@ %@", self.strongObj, self.assignObj, self.weakObj);


At the second NSLog statement, the strong and weak references will be nil, but the assign reference will not.





Jar Class Conflict Error of twilio-java-sdk-3.3.15-jar-with-dependencies and http-client-4.4.1,http-client-4.4.1

my two jars are conflicting and showing me the error for SolrHttpServer Instantiation for Solr-4.7.2.



java.lang.NoSuchMethodError: org.apache.http.impl.conn.SchemeRegistryFactory.createSystemDefault()Lorg/apache/http/conn/scheme/SchemeRegistry;



I checked and found that "http-client-4.4.1.jar", "http-core-4.4.1.jar" with a messaging API "twilio-java-sdk-3.3.15-jar-with-dependencies.jar"



Also, I have commons-httpclient-3.1.jar in my classpath.



The SchemeRegistryFactory class is present in these two jars. and also I have tried the http jars with other versions too.



any way to remove this conflict. ??



Tried Searching on Internet but didn't got success.





Android MediaCodec decoder configure error

I am trying to write a simple test application that takes camera input, encodes it and then decodes and displays the output.



In a function that does configuration, I do this:



mSurfaceManager = new SurfaceManager();
outputSurface = new Surface(mSurfaceManager.getSurfaceTexture());
outputSurface.eglMakeCurrent();

mCodec = MediaCodec.createDecoderByType(type);
mCodec.configure(format, outputSurface, null, 0);
mCodec.start();


When I run the code, in the logs, I see the following:



I/DecodeTest   (14319): [DecodeTestThread] CameraPipe19.java::start(): start camera (API 19 version) 960x540
I/DecodeTest (14319): [Thread-3212] Cam.java::prepareCamera(): 15000 15000
I/DecodeTest (14319): [Thread-3212] Cam.java::prepareCamera(): 15000 30000
I/DecodeTest (14319): [Thread-3212] Cam.java::prepareCamera(): no suitable FPS range found
I/DecodeTest (14319): [Thread-3212] Cam.java::prepareCamera(): picked FPS range 15000..15000
I/DecodeTest (14319): camera 0 size changed 960x540
I/DecodeTest (14319): [Thread-3212] Cam.java::prepareEncoder(): format: {frame-rate=12, bitrate=1000000, height=540, mime=video/avc, color-format=2130708361, i-frame-interval=600, width=960}
I/DecodeTest (14319): [Thread-3212] SurfaceManager.java::<init>(): texture is 1
I/DecodeTest (14319): [Thread-3212] SurfaceManager.java::getSurfaceTexture(): getSurfaceTexture: 1
I/DecodeTest (14319): [Thread-3212] SurfaceManager.java::getSurfaceTexture(): getSurfaceTexture: 1
I/DecodeTest (14319): [Thread-3212] Cam.java::drainEncoder(): encoder output format changed: {csd-1=java.nio.ByteArrayBuffer[position=0,limit=8,capacity=8], height=540, mime=video/avc, csd-0=java.nio.ByteArrayBuffer[position=0,limit=15,capacity=15], what=1869968451, width=960}
I/DecodeTest (14319): [Thread-3212] Cam.java::drainEncoder(): got codec config data
I/DecodeTest (14319): Encoder produced an I-frame
I/DecodeTest (14319): [Thread-3212] Cam.java::drainEncoder(): requesting an I-frame...
I/DecodeTest (14319): thread attached to JVM
I/DecodeTest (14319): [DecodeTestThread] Decoder.java::configure(): configure decoder type=video/avc
I/DecodeTest (14319): [DecodeTestThread] Render.java::loadShader(): Could not compile shader 35633:
I/DecodeTest (14319): [DecodeTestThread] Render.java::loadShader():
I/DecodeTest (14319): Encoder produced an I-frame
I/DecodeTest (14319): [DecodeTestThread] Decoder.java::decode(): decode exception: java.lang.NullPointerException


The particular text of significance is,




Render.java::loadShader(): Could not compile shader 35633:




I searched through some of the previous reports of the error message, but didn't get much clue. The display related parts are mostly cut and paste from here (thank you fadden). Any help in understanding the above error message?





↑このページのトップヘ